2012-08-06 227 views
0

我正在使用webgrid來顯示我的數據庫中的數據。問題在於排序選項不工作 這裏是我的WebGrid代碼webgrid排序不工作

@{ 
    var grid = new WebGrid(Model, canPage:true ,canSort:true, rowsPerPage :4); 
    grid.Pager(WebGridPagerModes.NextPrevious); 
     @grid.GetHtml(tableStyle: "webGrid", htmlAttributes: new { id = "datatable" }, 
     headerStyle: "webgrid-header", 

     selectedRowStyle : "webgrid-selected-row", 
     footerStyle : "webgrid-footer", 
       rowStyle: "webgrid-row-style", 
       alternatingRowStyle: "webgrid-alternating-row", 
     columns: grid.Columns(
    grid.Column(header: "", format: (item) => 

        Html.ActionLink("Détails", "Details", new { id = item.id_client }, new { @class = "details" }), style: "actions"), 

      grid.Column(header: "", format: (item) => Html.ActionLink("Modifier", "Edit", new { id = item.id_client }, new { @class = "modifier" }),style : "actions"), 

        grid.Column(header: "", format: (item) => Html.ActionLink("Supprimer", "Delete", new { id = item.id_client }, new { @class = "supprimer" }), style: "actions"), 

        grid.Column("Nom",canSort: true), 
        grid.Column("Prenom", "Prénom",canSort:true), 
     grid.Column("Email"))); 


         } 
+3

好的,這種排序不適用於特定列或所有列嗎?也看到[這個鏈接](http://yassershaikh.com/mvc-3-web-grid-sorting-not-working/)可以幫助你 – Yasser 2012-08-06 11:23:20

+0

是的,它只適用於一些列(它與int列和字符串一起工作列但不是全部) – Kira 2012-08-06 11:28:26

+0

我認爲問題是當網格包含多個頁面 – Kira 2012-08-06 11:37:24

回答

1

您可以嘗試添加名稱列的列表中爲您的WebGrid,例如:

var grid = new WebGrid(canPage:true ,canSort:true, rowsPerPage :4); 

grid.Bind(Model,columnNames: new[] { "Nom", "Prenom"}); //adding names of columns 

grid.Pager(WebGridPagerModes.NextPrevious); 
@grid.GetHtml(... 

有時候網頁網格可以」瞭解如何將您的模型與列綁定。

+0

嗨,詹姆斯,在我的webgrid 7000記錄there.i使用webgrid.in這個actionlink列排序不工作 – 2014-08-26 05:17:59

0

是的,詹姆斯的答案爲我工作。排序鏈接適用於某些列而不是其他列,並添加columnNames:使其正常工作。 Steve

+0

hi.i使用webgrid在我的application.in此操作鏈接列排序功能無法正常工作,任何人都可以幫助我。 – 2014-08-26 05:19:49