【问题标题】:loading columns dynamically for JQGrid using AjaxCall使用 AjaxCall 为 JQGrid 动态加载列
【发布时间】:2013-03-02 16:23:18
【问题描述】:

我需要将列动态加载到 Jqgrid 并尝试关注 jqGrid and dynamic column binding

我正在尝试使用 MVC。对于列名,我从表中获取(其中包含要在 GRID 中显示的列列表)并返回简单的 Json 数据。

我如何为 ColModel 实现。例如:我需要像这样动态发送 JSon 对象

     {name: 'Airport', formatter: UrlFmatter, width: 95, align: "center", index: 'AIRPORT', searchoptions: { sopt: ['eq', 'ne', 'cn']} }
  {name: 'Country', width: 100, align: "center", index: 'Country', searchoptions: { sopt: ['eq', 'ne', 'cn']} }

我的设计应该如何发送 json 来设置 colModel ?

我的 UrlFmatter 代码

function UrlFmatter(cellvalue, options, rowObject) {
                    return "<a href='DetailResult?airportname=" + options.rowId + "' >" + cellvalue + "</a>";
                }

我如何根据您对格式化和取消格式化的回答进行写作? 谢谢

【问题讨论】:

  • 您需要更改网格的状态准备好还是之前?
  • 我需要从 DB 发送数据并将其分配给 COlModel

标签: asp.net-mvc jqgrid


【解决方案1】:

我想您在 JSON 中发送有关格式化程序 (formatter: UrlFmatter) 的信息时遇到问题。 JSON 字符串不支持函数作为数据类型。解决问题的最简单方法似乎是我以与标准格式化程序相同的方式注册您的格式化程序。例如,您是否希望您的格式化程序具有名称 "myUrlFormatter" 您可以使用以下内容

(function ($) {
    'use strict';
    /*jslint unparam: true */
    $.extend($.fn.fmatter, {
        myUrlFormatter: function (cellValue, options) {
            // you should place here the code of 
            // your custom formatter UrlFmatter
        }
    });
    $.extend($.fn.fmatter.myUrlFormatter, {
        unformat: function (cellValue, options, elem) {
            // you should place here the code of 
            // your custom unformatter
        }
    });
}(jQuery));

您应该在jquery.jqGrid.min.js(或jquery.jqGrid.src.js 之后)添加代码。注册格式器后,您可以在colModel as 中使用它

{name: "Airport", index: "AIRPORT", formatter: "myUrlFormatter", width: 95,
    align: "center", searchoptions: { sopt: ["eq", "ne", "cn"]} }

所以formatter 属性的值将是字符串 (formatter: "myUrlFormatter") 而不是函数(formatter: UrlFmatter)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 2011-03-25
    相关资源
    最近更新 更多