• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Asp.net MVC 中 JqGrid 使用

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本地查询(Local):

@using Newtonsoft.Json
@using System.Net.Http

@{
    var result = from u in 查询语句略
                 select new
                 {
                     user_id = u.user_id,
                     user_email = u.user_email,
                     user_nicename = u.user_nicename,
                     user_status = u.user_status == 1 ? "已启用" : "未启用",
                     meta_key = m.meta_key,
                     meta_value = m.meta_value,
                     user_registered = u.user_registered,
                     option_description = o.option_description
                 };

    string strJsonRslt = JsonConvert.SerializeObject(result, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}

<script type="text/javascript">
    $("#gridTable").jqGrid({
            datatype: "local",
            width: '100%',
            height: '100%',
            colNames: ['编号', '用户名', '昵称', '状态', '权限', '出生日期'],
            colModel: [
                    { name: 'user_id', index: 'user_id', width: 60, sorttype: "int", editable: false },
                    { name: 'user_email', index: 'user_email', width: 180, editable: false },
                    { name: 'user_nicename', index: 'user_nicename', width: 80, editable: false },
                    { name: 'user_status', index: 'user_status', width: 60, sorttype: "string", editable: true, edittype: "select", editoptions: { value: "1:已启用;2:未启用" } },
                    { name: 'option_description', index: 'option_description', width: 100, editable: true, edittype: "select", editrules: { required: true }, editoptions: { value: '@strOptions' } },
                    { name: 'user_registered', index: 'user_registered', width: 180, sorttype: "date", editable: false }
            ],
            multiselect: true,
            multiselectWidth: "30px",
            sortname: 'user_id',
            sortorder: 'asc',
            viewrecords: true,
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: "#gridPager",
            caption: "用户信息列表"
        });
        
        var mydata = eval(@MvcHtmlString.Create(strJsonRslt));

        if (typeof (mydata) != "undefined") {
            for (var i = 0; i <= mydata.length; i++)
                jQuery("#gridTable").jqGrid('addRowData', i + 1, mydata[i]);
        }

        jQuery("#gridTable").trigger("reloadGrid");
</script>

<table id="gridTable"></table>
<div id="gridPager"></div>

联网查询(View):

<script type="text/javascript">
$("#gridTable").jqGrid({
        url: "/DSource/Load",
        mtype:"post",
        datatype: "json",
        width: '100%',
        height: '100%',
        colNames: ['编号', '报警', '名称', '监控项', '状态', '添加时间', '描述'],
        colModel: [
                { name: 'dsource_id', index: 'dsource_id', width: 30, sorttype: "int", editable: false },
                { name: 'dsource_alarm', index: 'dsource_alarm', width: 30, align: "center", sortable: false, editable: false, formatter: alarmFormatter },
                { name: 'dsource_name', index: 'dsource_name', width: 150, editable: false },
                { name: 'dsource_item', index: 'dsource_item', width: 70, editable: false },
                { name: 'dsource_status', index: 'dsource_status', width: 60, editable: false },
                { name: 'dsource_updatetime', index: 'dsource_updatetime', width: 150, sorttype: "date", editable: false },
                { name: 'dsource_description', index: 'dsource_description', width: 250, sorttype: "string", editable: false },
        ],
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        toolbar:[true,"top"],
        multiselect: true,
        multiselectWidth: "30px",
        sortname: 'dsource_id',
        sortorder: 'asc',
        viewrecords: true,
        rowNum: 10,
        rowList: [10,20,30],
        pager: "#gridPager",
        caption: "信息元列表",
    });
</script>

<table id="gridTable"></table>
<div id="gridPager"></div>

联网查询(Controller):

public JsonResult Load(bool? _search, string nd, int page, int rows, string sidx, string sord, string searchField, string searchString, string searchOper)
{
    var query = (from d in 查询语句略
                 select new
                 {
                     d.dsource_id,
                     dsource_alarm = new DSourceLogService().GetDSourceAlarmCnt(d.dsource_id, "", newEntity).ToString(),
                     d.dsource_name,
                     dsource_item = p.prop_description,
                     d.dsource_description,
                     dsource_status = d.dsource_status == "1" ? "启用" : "禁用",
                     d.dsource_expiredday,
                     dsource_alarmhigh = (d.dsource_alarmhigh == -65535 || d.dsource_alarmhigh == 65535) ? "未禁用" : d.dsource_alarmhigh.ToString(),
                     dsource_alarmlow = (d.dsource_alarmlow == -65535 || d.dsource_alarmhigh == 65535) ? "未禁用" : d.dsource_alarmhigh.ToString(),
                     dsource_alarmdeltadata = (d.dsource_alarmdeltadata == -65535 || d.dsource_alarmhigh == 65535) ? "未禁用" : d.dsource_alarmhigh.ToString(),
                     dsource_alarmidle = (d.dsource_alarmidle == -65535 || d.dsource_alarmhigh == 65535) ? "未禁用" : d.dsource_alarmhigh.ToString(),
                     d.dsource_formula,
                     dsource_updatetime = d.dsource_updatetime.ToString("yyyy-MM-dd HH:mm:ss")
                 }).AsQueryable();

    page = page <= query.Count() / rows + 1 ? page : 1;

    var filter = query.OrderUsingSortExpression(string.Format("{0} {1}", sidx, sord)).Skip(rows * (page - 1)).Take(rows);

    return this.Json(new { rows = filter, page = page, total = query.Count() / rows + 1, records = query.Count() }, JsonRequestBehavior.AllowGet);
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
asp.net中FCKeditor的调用(31)发布时间:2022-07-10
下一篇:
[转]ASP.NET中将GridView导出到Excel文件中发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap