• Asp.net MVC 中 JqGrid 使用


    本地查询(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",
                 '100%',
                height: '100%',
                colNames: ['编号', '用户名', '昵称', '状态', '权限', '出生日期'],
                colModel: [
                        { name: 'user_id', index: 'user_id',  60, sorttype: "int", editable: false },
                        { name: 'user_email', index: 'user_email',  180, editable: false },
                        { name: 'user_nicename', index: 'user_nicename',  80, editable: false },
                        { name: 'user_status', index: 'user_status',  60, sorttype: "string", editable: true, edittype: "select", editoptions: { value: "1:已启用;2:未启用" } },
                        { name: 'option_description', index: 'option_description',  100, editable: true, edittype: "select", editrules: { required: true }, editoptions: { value: '@strOptions' } },
                        { name: 'user_registered', index: 'user_registered',  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",
             '100%',
            height: '100%',
            colNames: ['编号', '报警', '名称', '监控项', '状态', '添加时间', '描述'],
            colModel: [
                    { name: 'dsource_id', index: 'dsource_id',  30, sorttype: "int", editable: false },
                    { name: 'dsource_alarm', index: 'dsource_alarm',  30, align: "center", sortable: false, editable: false, formatter: alarmFormatter },
                    { name: 'dsource_name', index: 'dsource_name',  150, editable: false },
                    { name: 'dsource_item', index: 'dsource_item',  70, editable: false },
                    { name: 'dsource_status', index: 'dsource_status',  60, editable: false },
                    { name: 'dsource_updatetime', index: 'dsource_updatetime',  150, sorttype: "date", editable: false },
                    { name: 'dsource_description', index: 'dsource_description',  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);
    }
  • 相关阅读:
    nios sgdma(Scatter-Gather dma)示例
    关于nios 中printf 的问题
    Nios II 系统时钟timestamp的应用
    DMA在FPGA的应用之我见
    PIO Core
    VGA接口时序约束
    时序分析,重中之重,柳暗花明又一村 搞定美女了问题
    深入浅出VGA和DVI接口
    基于FPGA的VGA可移植模块终极设计
    理解FPGA中的RAM、ROM和CAM;ROM、RAM、DRAM、SRAM、FLASH
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/3025936.html
Copyright © 2020-2023  润新知