0

I'm using webgrid to show data from my data base. The problem is that sort option is not working Here is my webgrid code

@{
    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")));


                        }
Kira
  • 1,153
  • 4
  • 28
  • 63

2 Answers2

1

You can try add the list of name columns for your webgrid, for example:

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(...

Sometimes web grid can't understand how bind your model with columns.

Spudley
  • 166,037
  • 39
  • 233
  • 307
James
  • 51
  • 1
0

Yes, James's answer worked for me. The sort links were working for some of the columns and not others, adding the columnNames: made it work properly. Steve

Steve
  • 11
  • 1