9

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

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

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

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

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

提前致谢。

4

1 回答 1

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");
于 2011-03-18T14:09:48.600 回答