Asp.net mvc 4 基于剑道UI网格Mvc的过滤

Asp.net mvc 4 基于剑道UI网格Mvc的过滤,asp.net-mvc-4,kendo-ui,kendo-grid,Asp.net Mvc 4,Kendo Ui,Kendo Grid,这是我的剑道网格Post方法,我想对剑道网格中的测试名称执行过滤。我曾尝试使用javscript,但它对我不起作用 控制器 [HttpPost] public ActionResult TestNotification(DataSourceRequest command) { EAssessmentNew.BAL.StudentBal studBal = new EAssessmentNew.BAL.StudentBal(); int stud

这是我的剑道网格Post方法,我想对剑道网格中的测试名称执行过滤。我曾尝试使用javscript,但它对我不起作用

控制器

  [HttpPost]
    public ActionResult TestNotification(DataSourceRequest command)
    {
        EAssessmentNew.BAL.StudentBal studBal = new EAssessmentNew.BAL.StudentBal();
        int studentId = Convert.ToInt32(studBal.getStudentId(Session["sname"].ToString()));

        PageList<Test> TestDetails = studBal.testDetails(studentId, command.Page - 1, command.PageSize);

        var gridModel = new DataSourceResult
        {
            Data = TestDetails.Select(x =>
            {
                var TestModel = new Test();
                TestModel.Test_Id = x.Test_Id;
                TestModel.Test_Name = x.Test_Name;
                TestModel.Test_Date = x.Test_Date;
                TestModel.Start_Time = x.Start_Time;
                TestModel.End_Time = x.End_Time;
                return TestModel;
            }),
            Total = TestDetails.TotalCount,
        };
        return Json(gridModel);


    }

Kendo JQuery On View
[HttpPost]
公共操作结果测试通知(DataSourceRequest命令)
{
EAssessmentNew.BAL.StudentBal studBal=新EAssessmentNew.BAL.StudentBal();
int studentId=Convert.ToInt32(studBal.getStudentId(Session[“sname”].ToString());
pagelisttestdetails=studBal.TestDetails(studentId,command.Page-1,command.PageSize);
var gridModel=新数据源结果
{
数据=测试详细信息。选择(x=>
{
var TestModel=new Test();
TestModel.Test\u Id=x.Test\u Id;
TestModel.Test_Name=x.Test_Name;
TestModel.Test_Date=x.Test_Date;
TestModel.Start\u Time=x.Start\u Time;
TestModel.End_Time=x.End_Time;
返回测试模型;
}),
总计=TestDetails.TotalCount,
};
返回Json(gridModel);
}
剑道JQuery在视图上


$(文档).ready(函数(){
$(“#测试网格”).kendoGrid({
数据源:{
键入:“json”,
运输:{
阅读:{
url:@Html.Raw(url.Action(“TestNotification”、“Student”)”,
类型:“POST”,
数据类型:“json”,
数据:“”,
}
},
模式:{
数据:“数据”,
总计:“总计”,
错误:“错误”
},
错误:函数(e){
显示网格错误(e);
这个.cancelChanges();
},
页面大小:2,
对,,
是的,
服务器排序:true
},
可分页:{
刷新:是的,
页面大小:[10、20、30]
},
可编辑:{
确认:假,
模式:“内联”
},
可滚动:false,
栏目:[
{
字段:“测试名称”,
标题:“姓名”,
可过滤:正确,
宽度:10
//模板:“”
},
{
字段:“测试日期”,
标题:“测试日期”,
//模板:“#=kendo.toString(kendo.parseDate(测试日期,“dd/MM/yyyy”))#”,
模板:“#=kendo.toString(新日期(parseInt(Test#Date.substr(6)),'dd-MM-yyyy')#”,
宽度:10
},
{
字段:“开始时间”,
标题:“开始时间”,
宽度:10,
//模板:“”
},
{
字段:“结束时间”,
标题:“结束时间”,
宽度:10,
//模板:“”
},
{
字段:“测试Id”,
标题:“行动”,
宽度:10,
模板:“”
}]
});
});

以上是我对剑道网格的jquery我如何在网格中对测试名称执行过滤我尝试过使用javascript我在控制器上有一个GetTestList方法,它返回我一个测试列表,但从过滤器的角度来看它不起作用。如果您返回所有正在执行的数据,请提供任何帮助流动的

$("#test-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("TestNotification", "Student"))",
                                    type: "POST",
                                    dataType: "json",
                                    data: '',
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors"
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                this.cancelChanges();
                            },
                            pageSize: 2,
                            //serverPaging: true,
                            //serverFiltering: true,
                            //serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            pageSizes: [10, 20, 30]
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        filterable: true,
                        sortable: true,
                        columns: [
                            {
                                field: "Test_Name",
                                title: "Name",
                                filterable: true,
                                width: 10
                            },
                            {
                                field: "Test_Date",
                                title: "Test Date",
                                width: 10
                            },
                            {
                                field: "Start_Time",
                                title: "Start Time",
                                width: 10,

                            },
                            {
                                field: "End_Time",
                                title: "End Time",
                                width: 10,
                            },
                         {
                             field: "Test_Id",
                             title: "Action",
                             width: 10,
                             template: '<a  title="Apply" href="/Student/ApplyForTest?TestId=#=Test_Id#">Click To Apply</a>'

                         }]
                    });
当它们被启用时,上面将调用读取操作,并传递页面大小、筛选对象等。因此,您应该在读取操作中接受这些参数,并返回过滤后的数据或页面数据

我将把read写为一个函数,这样我就可以管理发送给动作的参数

transport: {
            read: function (options) {
// the option will have pagesize (eg:option.pagesize ) when paging
 // the option will have filter OBJ (eg:option.filter[]) when filtering 
                $.ajax({
                    url: "@Html.Raw(Url.Action("TestNotification", "Student"))",,
                    dataType: "json",
                    data: {pageSize:option.pagesize }, // send the data accordingly (not sure exact syntax but its available in the option parameter)
                    cache: false,
                    success: function (result) {
                        options.success(result);
                    },
                    error: function (result) {
                        options.error(result);
                    }
                });
            },
} 

假设数据库中有50条记录,如果返回所有50条记录,则不需要进行服务器筛选或分页。但是,如果您只返回50条记录中的10条,则需要服务器分页和筛选来筛选或对所有记录进行分页。你现在有什么选择?请立即写入我的数据库中的4条记录我在一页上显示2条,在另一页上显示2条,我的问题是我想在测试名称上设置过滤器,以便用户可以轻松找到所需的结果。你的意思是,当加载数据时,你需要过滤测试名称或激活该列的过滤器?是的,现在你得到了我的数据加载到网格中,我想在测试名称旁边放置过滤器,这样我就可以根据需要进行过滤。很酷,您不需要服务器分页、服务器过滤或服务器排序。正如我所做的,将“filterable:true”放在列之前。您不需要对其他列进行筛选吗?如果没有,则为其他列添加“filterable:false”
                                //serverPaging: true,
                                //serverFiltering: true,
                                //serverSorting: true
transport: {
            read: function (options) {
// the option will have pagesize (eg:option.pagesize ) when paging
 // the option will have filter OBJ (eg:option.filter[]) when filtering 
                $.ajax({
                    url: "@Html.Raw(Url.Action("TestNotification", "Student"))",,
                    dataType: "json",
                    data: {pageSize:option.pagesize }, // send the data accordingly (not sure exact syntax but its available in the option parameter)
                    cache: false,
                    success: function (result) {
                        options.success(result);
                    },
                    error: function (result) {
                        options.error(result);
                    }
                });
            },
}