Sorting dojo datagrid自定义排序服务器端
我正在使用dojo.data.ItemFileWriteStore绘制一个dojo数据网格(工作正常),网格可以正常显示。我使用的是客户端排序,这也很好。 但现在我需要更改排序,并在服务器端执行此操作。为此,我尝试使用onHeaderCellClick事件,使用它我可以运行javascript函数。。 差不多Sorting dojo datagrid自定义排序服务器端,sorting,datagrid,dojo,header,server-side,Sorting,Datagrid,Dojo,Header,Server Side,我正在使用dojo.data.ItemFileWriteStore绘制一个dojo数据网格(工作正常),网格可以正常显示。我使用的是客户端排序,这也很好。 但现在我需要更改排序,并在服务器端执行此操作。为此,我尝试使用onHeaderCellClick事件,使用它我可以运行javascript函数。。 差不多 gridInfo = { store: myJsonStore, structure: myStructure o
gridInfo = {
store: myJsonStore,
structure: myStructure
onHeaderCellClick:getSortedTable
};
下面是getSortedTable函数,我想用它对服务器进行另一次调用——传递单元格名、表名和排序顺序(asc或desc)
但是我能从'e'参数中得到的唯一信息是单元格名,可能是表名
谢谢,您最好修改数据存储以处理服务器端排序而不是网格(例如,将排序条件作为查询参数附加到由
fetch()
触发的XHR调用,而不是对结果集客户端排序)。网格的行为应该与客户端排序完全相同,因为它只反映数据存储的排序顺序
从dojo.data.api.Read
关于fetch()
:
我想你可以换店了。我将网格与jsonRestStore一起使用。因此,每当我通过单击列来更改排序时,网格就会启动一个请求 这是我的网格
require([
"dojox/grid/EnhancedGrid",
"dojox/data/JsonRestStore",
"dojox/grid/enhanced/plugins/NestedSorting",
"dojo/domReady!",
"dojox/grid/cells/dijit"
], function(DataGrid, JsonRestStore) {
dataStore = new JsonRestStore({
target: "/url_to_your_be"
});
grid = new DataGrid({
store: dataStore,
plugins: {"nestedSorting": true},
query: "?something=1",
structure: [
{
defaultCell: { editable: false},
cells: [
{ name: "col 1", field: "col_1", width: "50px"},
{ name: "col 2", field: "col_2", width: "50px"}
]
}
],
selectionMode: "single",
sortFields: [{attribute: 'col_1', descending: false},{attribute: 'col_2', descending: false}]
}, "yourGridId");
grid.startup();
});
sortFields用于在第一次加载时设置排序,如果不需要,可以忽略它
每次单击标题时,它都会发送一个请求,如
http//www.yourwebsite.com/url\u to\u your\u be/?something=1&sort(+col\u 1,+col\u 2)
即使您正在更改查询
var grid = dijitRegistry.byId('yourGridId');
grid.setQuery("?something=2");
请求将被删除
`http//www.yourwebsite.com/url_to_your_be/?something=2&sort(+col_1,+col_2)`
现在您可以在BE中拆分$\u GET数据并进行排序
我的BE正在以json对象的形式发送数据:
[{"col_1": 1, "col_2": "something"},...]
使用数据范围的标题:
Content-Range: items=0-10/100
我为迟来的答复道歉。我还需要回到这个问题上来。到现在为止,我还被其他事情缠住了。我将尝试执行取回并返回我发现的内容。。。谢谢你的回复!!
[{"col_1": 1, "col_2": "something"},...]
Content-Range: items=0-10/100