dojo datagrid自定义排序服务器端 [英] dojo datagrid custom sorting server side

查看:178
本文介绍了dojo datagrid自定义排序服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dojo.data.ItemFileWriteStore来绘制一个dojo datagrid(它工作正常),网格正常显示。我正在使用客户端排序,这也正常工作。
,但现在我需要更改排序并做那个服务器端。为此,我试图使用onHeaderCellClick事件,使用它可以运行一个javascript函数..



$ $ $ $ $ $ $ $ c> gridInfo = {
store:myJsonStore,
结构:myStructure
onHeaderCellClick:getSortedTable
};

现在这里是我要用来再次调用服务器的getSortedTable函数 - 传递单元格名称,表名称和排序顺序(asc或desc)。

  function getSortedTable(e)
{
var cellName = e.cell.name;
var tableName =?
var sortOrder =?
// getSortedTablefromServer(cellName,sortOrder,tablename)
}

但是只有thihng我能够从'e'参数中取出是单元名称,可能是表名。


  1. 如何获取或保持天气跟踪,这将是用户要求的升序或降序。

  2. 另外 - 如何在列的标题上显示小箭头,向用户显示数据是降序还是升序?

任何帮助都非常感激!!



谢谢,

解决方案

我想你可能会改变你的商店。我正在使用网格与jsonRestStore代替。因此,每次通过点击列更改排序时,网格都会启动一个请求。



这是我的网格

  require([
dojox / grid / EnhancedGrid,
dojox / data / JsonRestStore,
dojox / grid / enhanced /插件/ 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:[
{名称:col 1,字段:col_1,width:50px},
{name:col 2,field:col_2,width:50px}
]
}
],
selectionMode:singl e,
sortFields:[{attribute:'col_1',descending:false},{attribute:'col_2',descending:false}]
},yourGridId);
grid.startup();
});

sortFields用于在首次加载时设置排序,如果不需要,可以忽略



每次您在标题中点击它都会发送一个请求,如



http // www.yourwebsite.com / url_to_your_be /?something = 1& sort(+ col_1,+ col_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中分割$ _GET数据,并进行排序



我的BE将数据发送为json对象:

  [{col_1:1,col_2:something},...] 

与数据范围的标题:

 内容范围:items = 0-10 / 100 


I am using dojo.data.ItemFileWriteStore to draw a dojo datagrid (which works fine) and the grid shows properly. I was using client side sorting and that was also working fine. but now I need to change the sorting and do that server side. For this I am trying to use onHeaderCellClick event, using which I am able to run a javascript function.. something like

 gridInfo = {
            store: myJsonStore,
            structure: myStructure
            onHeaderCellClick:getSortedTable
         };

Now here is the getSortedTable function which I want to use to make another call to the server - passing the cell name, Table Name and the sort Order (asc or desc).

 function getSortedTable(e)
    {
  var cellName = e.cell.name;
            var tableName = ?
            var sortOrder = ?
          // getSortedTablefromServer(cellName, sortOrder, tablename)
    }

but the only thihng I am able to get out of from the 'e' parameter is the cell Name and may be the table Name.

  1. How can I get or keep a track of weather it will be ascending order required by the user or is it descending order.
  2. Also - how will I show the little arrow on the header of the column to show the user that the data is in descending or ascending?

Any help is highly appreciated!!

Thanks,

解决方案

I think you may change your store. I'm using the grid with the jsonRestStore instead. So the grid is starting a request every time I change the sorting by clicking on a column.

Here is my grid

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 is for setting the sort on your first load and can be ignored if you don't need it.

Every time you click in the header it is sending a request like

http//www.yourwebsite.com/url_to_your_be/?something=1&sort(+col_1,+col_2)

Even if you are changing the query

var grid = dijitRegistry.byId('yourGridId');
grid.setQuery("?something=2");

the request will be

`http//www.yourwebsite.com/url_to_your_be/?something=2&sort(+col_1,+col_2)`

Now you can split the $_GET data in your BE and do the sort

My BE is sending the data as json object:

[{"col_1": 1, "col_2": "something"},...]

with the header of data range:

Content-Range: items=0-10/100

这篇关于dojo datagrid自定义排序服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆