WebGrid需要逐列过滤

时间:2017-07-04 15:51:15

标签: c# .net asp.net-mvc webgrid

这里我有一个WebGrid,我需要像Grid.Mvc中那样使用Filterable()的列式过滤。请帮助。感谢。

 <div id="DivGrid">
@{
    var grid = new WebGrid(source: Model, canPage: true, canSort: true, rowsPerPage: 10, defaultSort: "Employee ID");
    grid.SortDirection = SortDirection.Descending;
    if (Model.Count() > 0)
    {
        <div class="moveRight"><strong> @ViewBag.SearchParameter</strong> | @grid.TotalRowCount @Html.Label("Record(s) found")</div>
        @grid.GetHtml(tableStyle: "PGrid", headerStyle: "Header", alternatingRowStyle: "altRow", htmlAttributes: new { id = "DataTable" }, columns: grid.Columns(
            grid.Column("Employee_ID", "Employee ID", format: @<text>  <span class="display-mode grid-filter-btn">@item.Employee_ID </span> <label id="EmployeeID" class="edit-mode grid-filter-btn">@item.Employee_ID</label> </text>, style: "col1Width", canSort:true),
            grid.Column("First_Name", "First Name", format: @<text>  <span class="display-mode"> <label id="lblFirstName">@item.First_Name</label> </span> <input type="text" id="FirstName" value="@item.First_Name" class="edit-mode" /></text>, style: "col2Width", canSort:true),
            grid.Column("Last_Name", "Last Name", format: @<text> <span class="display-mode"> <label id="lblLastName">@item.Last_Name</label> </span>  <input type="text" id="LastName" value="@item.Last_Name" class="edit-mode" /> </text>, style: "col2Width", canSort:true),
            grid.Column("Date_Of_Birth", "Date Of Birth", format: item => ((item.Date_Of_Birth == null) ? "" : item.Date_Of_Birth.ToString("MM/dd/yyyy")), style: "DateOfBirth"),
            //grid.Column("Date_Of_Birth", "Date Of Birth", format: item => ((item.Date_Of_Birth == null) ? "" : item.Date_Of_Birth.ToString("MM/dd/yyyy")) ),
            grid.Column(header: "Action", canSort: false, style: "action", format: @<text>                
            <button class="edit-user display-mode glyphicon glyphicon-edit"> Edit</button>
            <button class="display-mode delete-item glyphicon glyphicon-trash"> Delete</button>
            <button class="save-user edit-mode glyphicon glyphicon-save"> Save</button>
            <button class="cancel-user edit-mode glyphicon glyphicon-remove-sign"> Cancel</button></text>)));
    }
    else
    {
        <hr />@Html.Label("No, Record(s) not found")<<hr />
    }
}

1 个答案:

答案 0 :(得分:0)

据我所知,没有内置选项来过滤Asp.net MVC中的数据。您需要编写自定义代码。请检查此链接 WebGrid Paging,Sorting and Filtering in ASP.NET MVC