我正在考虑添加jqgrid,在我从下拉列表中选择一个值后将得到填充(比如状态:打开,进行中,关闭,重新启动......)但是如何将选择列表绑定为JQgrid的过滤器我被卡住了逻辑如何实现它
<script type="text/javascript">
$('document').ready(function () {
//
jQuery('#list').jqGrid({
url: '../api/JqGridTask?UserId=@ViewBag.UserId',
datatype: 'json',
mtype: 'Get',
jsonReader: { repeatitems: false },
colNames: ['UserName', 'TaskId', 'TaskName', 'TaskStatus'],
colModel: [
{ name: 'UserName', index: 'UserName', width: 75 },
{ name: 'TaskId', index: 'TaskId', width: 90 },
{ name: 'TaskName', index: 'TaskName', width: 100, formatter: showLink },
{ name:'TaskStatus',index:'TaskStatus',width:100}
],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
}).navGrid('#pager', { edit: false, add: false, del: false });
});
function showLink(cellvalue, options, rowObject) {
return '<a href = "/User/EditTask?TaskId=' + rowObject.TaskId + '">' + rowObject.TaskName + '</a>';
}
![C:\Users\shekhar.pankaj\Desktop\Capture.png
我的控制器代码是......................
public class JqGridTaskController : ApiController
{
public jsontext GetAllGridData(int UserId,string sidx, string sord, int page = 1, int rows = 1)
{
var jsonType = new jsontext();
using (var model = new TaskManagerEntities())
{
jsonType.rows = (from dtUser in model.UserTasks
where dtUser.UserId==UserId
//here i want to use my conditions that will get returned from dropdown
select new TaskUserGrid
{
UserName = dtUser.User.FirstName + dtUser.User.LastName,
TaskId=dtUser.Task.TaskId,
TaskName=dtUser.Task.Title,
TaskStatus=dtUser.Task.TaskStatu.StatusType
}).ToList();
return jsonType;
}
}
/// <summary>
///
/// </summary>
public class jsontext
{
public int total { get; set; }
public int page { get; set; }
public int records { get; set; }
public List<TaskUserGrid> rows { get; set; }
}