Results 1 to 6 of 6

Thread: Destroying Grid and recreating with new data

  1. #1
    Ext User
    Join Date
    May 2007
    Posts
    69

    Default Destroying Grid and recreating with new data

    I'm able to successfully refresh a grid with new data, but the height of the grid isn't auto sizing with the new resultset. So what is happening is that the first time the grid appears it sizes itself to the data. The next time its refreshed (with more data), it is remaining the same size and my data has to scroll. Does anyone know what i may be doing wrong? (i'm using ext 1.1 beta)

    Here is my code:
    Code:
    if(grid)
    {
    	// Remove grid view event listeners from ds
     var grid_view = grid.getView();
    grid_view.ds.un('load', grid_view.onLoad, grid_view);
    grid_view.ds.un('datachanged', grid_view.onDataChange, grid_view);
    							  
    grid_view.ds.un('add', grid_view.onAdd, grid_view);
    grid_view.ds.un('remove', grid_view.onRemove, grid_view);
    grid_view.ds.un('update', grid_view.onUpdate, grid_view);
    grid_view.ds.un('clear', grid_view.onClear, grid_view);
    grid.destroy(true);    // Destroy the grid
    }
     else
    {
    // create the Data Store
     	var searchurl = "newconnect.aspx?begindate=" + begin + "&enddate=" + end;
    	var ds = new Ext.data.Store({
    	// load using HTTP
    	proxy: new Ext.data.HttpProxy({url: searchurl}),
    	// the return will be XML, so lets set up a reader
    	reader: new Ext.data.XmlReader({
    		   record: 'mover',
    		 id: 'moverid',
    		 totalRecords: '@total'
    	}, [
    	// set up the fields mapping into the xml doc
    	// The first needs mapping, the others are very basic
    	 {name: 'firstname', mapping: 'moverattributes > firstname'},
    	'lastname', 'dob', 'movedate'
    	  ])
    	});
    	 var cm = new Ext.grid.ColumnModel([
    	header: "First Name", width: 120, dataIndex: 'firstname'},
    	{header: "Last Name", width: 180, dataIndex: 'lastname'},
    	{header: "Date of Birth", width: 115, dataIndex: 'dob'},
    	{header: "Move Date", width: 100, dataIndex: 'movedate'}
    	]);
    	
    	cm.defaultSortable = true;
    	 // create the grid
    	var grid = new Ext.grid.Grid('example-grid', {
    	ds: ds,
    	cm: cm,
    	enableColLock:false,
    	monitorWindowResize : true,
    	loadMask: true
    	});
    	
    	grid.render();
    	
    	var gridFoot = grid.getView().getFooterPanel(true);
    	 // add a paging toolbar to the grid's footer
    	var paging = new Ext.PagingToolbar(gridFoot, ds, {
    	pageSize: 25,
    	displayInfo: true,
    	displayMsg: 'Displaying topics {0} - {1} of {2}',
    	emptyMsg: "No results to display"
    	});
    	
    	ds.load();
    	
    	grid.on('rowdblclick', function(grid, rowIndex, e) {
    	 var id = ds.data.items[rowIndex].id;
    	Ext.fly(grid.getView().getRow(2).highlight);
    	MOL.openNewTab(id);
    	});
     }
    }
    Last edited by tryanDLS; 26 Jun 2007 at 7:10 PM. Reason: Post your code in CODE tags!

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854

    Default

    Why are you destroying the grid - is the resultset changing? Did you try using reconfigure? You're unhooking the view's handlers - do you ever reattach them?

  3. #3
    Ext User
    Join Date
    May 2007
    Posts
    69

    Default

    The data is changing, but the type of data isn't...are you suggesting that I don't need to destroy the grid, but only refresh the content?..if so, how would i accomplish this?

    I can't seem to find any information on reconfigure...would you be able to point me in the right direction?

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854

    Default

    If you're cm isn't changing, you can just call load again to load different data. You can change the properties of the proxy if you need to. Reconfigure is a (currently undocumented) function of the grid which takes a new datasource and colModel and rebuilds the grid - in your case, I don't think you need to go this route.

  5. #5
    Ext User
    Join Date
    May 2007
    Posts
    69

    Default

    Thank you. I will try this tonight!

  6. #6
    Ext User
    Join Date
    May 2007
    Posts
    69

    Default

    It's still not working...i'm not having a problem reloading the data, it's just that the grid isn't resizing to show all the data. Here is the code for when the grid exists already...
    (thank you for your assistance)


    if(grid)
    {
    var searchurl = "newconnect.aspx?begindate=" + begin + "&enddate=" + end;
    var ds = new Ext.data.Store({
    // load using HTTP
    proxy: new Ext.data.HttpProxy({url: searchurl}),
    reader: new Ext.data.XmlReader({
    record: 'mover',
    id: 'moverid',
    totalRecords: '@total'
    }, [
    // set up the fields mapping into the xml doc
    // The first needs mapping, the others are very basic
    {name: 'firstname', mapping: 'moverattributes > firstname'},
    'lastname', 'dob', 'movedate'
    ])
    });

    ds.load();
    }
    else

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •