1

我正在考虑添加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; }
    }
4

1 回答 1

0

对不起Guyz,如果你来到这里......经过大量学习......我能够解决我的问题......你可以删除这个问题,但对于像我这样的初学者......这会有所帮助(我认为)

 $('document').ready(function () {
//this Will Call function on every selected values from Drop Down
        $("#statusList").change(function () {
            var selectedValue = $(this).val();
            $("#list").GridUnload();
            $("#list").trigger('reloadGrid');
            $.ajax(gridBind(selectedValue))
        });

    });

//this function will get called ..and here i will request data for The Grid
    function gridBind(selectedValue) {
        jQuery('#list').jqGrid({
            url: '../api/JqGridTask?UserId=' + @ViewBag.UserId +'&selectedValue=' + selectedValue,
            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>';
    }

</script> 

任何方式人们感谢....感谢 StackOverFlow ...

于 2014-01-31T08:21:43.250 回答