当两个网格位于同一页面时进行排序

时间:2011-03-18 09:12:51

标签: asp.net-mvc-3 webgrid

在我的页面上,我有两个webGrids。当我单击一个对该列进行排序时,两个网格都在该列上排序。对仅在一个列中的列进行排序,根本不排序。

我注意到排序的工作原理是使标题成为同一页面的链接,在查询字符串中包含列和方向。这解释了两个网格都受到影响。我想知道webGrid是否有一些功能可以解决我的问题,或者我应该自己修复它。

我计划“自己修复”的方法是首先通过设置htmlAttributes为表标记添加id属性。然后我将使用jQuery为每个webgrid找到这个id,并将该id包含在links参数中。然后当加载带有网格的页面时,我将根据这些参数强制设置要排序的列。

在我看来,webGrid并不是设计在另一个webGrid的页面上。但是,我觉得在我的情况下,这是需要的。我更喜欢使用一些标准方式(内置或其他人使用)。

所以问题是,最好的方法是什么?如果没有最好的方法,我的方式是一个好方法(我忘了什么)?

提前致谢。

1 个答案:

答案 0 :(得分:15)

我认为你需要设置以下属性:

string fieldNamePrefix = null 
//The value which prefixes the default querystring fields

string pageFieldName = null 
//A value that replaces the default querystring page field 


var grid1 = new WebGrid(canPage: true,  canSort: true, ajaxUpdateContainerId: "grid1", fieldNamePrefix:"g1",pageFieldName: "p1");

var grid2 = new WebGrid(canPage: true,  canSort: true, ajaxUpdateContainerId: "grid2", fieldNamePrefix:"g2",pageFieldName: "p2");
相关问题