I hate to post what is no doubt something totally obvious, yet after going through the examples and forums I can't find a solution.
In my grid I have an extra parameter (table) that holds, obviously, the table name. This works fine for the first page, but when I use the paging toolbar this value is not sent. I've tried putting this parameter into the PagingToolbar but it doesn't ever seem to see it. Everything else works fine, if I hard code the table name then paging works fine, but I want it to be flexible. Can someone look at my code and tell me what I'm missing please.
Unrelated, documentation question. As you can see from my code the ID field is hidden. I just guessed this value and it worked (hurrah for common sense). But I don't actually know where the different options for the columns are documented. I've gone through most of the grid documentation and I can't find it. width, renderer, sortable, resizable, locked, etc, etc it's easy enough to work them all out from the examples and such, but where are they in the documentation? I'm sure i'm missing something incredibly obvious...
Thanks.
Thanks.
In my grid I have an extra parameter (table) that holds, obviously, the table name. This works fine for the first page, but when I use the paging toolbar this value is not sent. I've tried putting this parameter into the PagingToolbar but it doesn't ever seem to see it. Everything else works fine, if I hard code the table name then paging works fine, but I want it to be flexible. Can someone look at my code and tell me what I'm missing please.
//grid1.js
var myGrid = function() {
return {
init: function() {
//we enable the QuickTips for the later Pagebar
Ext.QuickTips.init();
// create the Data Store
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'grid1_data.asp'}),
reader: new Ext.data.JsonReader({
root: 'myFriends',
totalProperty: 'totalCount',
id: 'id'
},
[
{name: 'ID', mapping: 'id', type: 'int'},
{name: 'Name', mapping: 'name', type: 'string'},
{name: 'Sector', mapping: 'sectorName', type: 'string'}
]),
// turn on remote sorting
remoteSort: true
});
//we set the deafault sort to the id ascending
ds.setDefaultSort('ID', 'asc');
// now we create the Grid Columns
var cm = new Ext.grid.ColumnModel([
{header: "ID", dataIndex: 'ID', hidden:true},
{header: "Name", dataIndex: 'Name', width: 100, sortable: true},
{header: "Sector", dataIndex: 'Sector', width: 140, sortable: true}
]);
// by default columns are sortable
cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.Grid('tutorial-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:true
});
// render the Grid
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: 100});
ds.load({params:{start:0, limit:100, table:'asset'}});
}
};
}();
Ext.EventManager.onDocumentReady(myGrid.init, myGrid, true);
Thanks.
Thanks.
|
#
2
|
|
The parameters in load are only used for that one load. Use ds.baseParams = {table: 'asset'} (either as given or in the config).
|
|
#
3
|
|
Attach a listener to the beforeload event for the datastore.
ds.on('beforeload', function() {
ds.baseParams = {
sort: cm.getIndexById(ds.sortInfo.field) * ((ds.sortInfo.direction.toUpperCase() == 'DESC') ? -1 : 1)
, search: search.getValue()
};
});
|
|
#
4
|
|
I did it this way (see "setFilter"). Mabye someone can comment on this if it is the wrong to do, but it works out quite well:
myGrid = function() {
var grid; //grid itself
var ds; // datastore
return {
init : function() {
...
ds = new Ext.data.Store({
// load a simple http proxy
proxy: new Ext.data.HttpProxy({
url: 'resp_calls.php'
}),
reader: reader,
// turn on remote sorting
remoteSort: true
});
...
}, // end init
// pass over add. param for XHR request
setFilter: function(afilter) {
ds.baseParams = afilter;
return true;
}
} // end return
}(); // endfunction myGrid
myGrid.setFilter({table: 'asset'});
or///
myGrid.setFilter({table: 'asset', chair: 'asset2'});
|
|
#
5
|
|
Yes, that's certainly one way of doing it. It's important to understand that the baseParams aren't going to be dynamic (change, as needed, for every new XHR request that's generated for the grid), but each XHR request will use whatever state the baseParams is currently in.
|
本文讨论了在使用ExtJS框架时遇到的问题:如何在分页操作中正确传递额外参数(如表名)到服务器端。作者分享了自己的代码实现,并通过社区交流找到了解决方案,包括设置`baseParams`来确保每次请求都包含必要的参数。

3761

被折叠的 条评论
为什么被折叠?



