本文介绍了使用AjaxCall为JQGrid动态加载列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将列动态加载到Jqgrid,并尝试遵循 jqGrid和动态列绑定

I need to load columns to Jqgrid Dynamically and am trying to follow jqGrid and dynamic column binding

正在尝试使用MVC.从表中获取列名(这将在GRID中显示一个列的列表),并返回Json数据,这很简单.

Am trying in MVC. for Column name am fetching from Table(Which has a list of Columns to be displayed in GRID) and returning the Json data which is straightforward.

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

How do i implement for ColModel. For ex: i need to send JSon object like this dynamically

     {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?

How my design should be to send json to set the colModel ?

我的UrlFatter模式代码

My UrlFmatter code

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

我如何根据您的答案来格式化和取消格式化?谢谢

How do i write as per your answer for formatting and unformatting ?Thanks

推荐答案

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

I suppose that you have the problem with sending information about the formatter (formatter: UrlFmatter) inside of JSON. JSON strings don't support functions as the type of data. The most easy way to solve the problem seems me registering your formatter in the same way as standard formatters. For example is you want that your formatter have the name "myUrlFormatter" you can use the following

(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中以

You should include the code after jquery.jqGrid.min.js (or after jquery.jqGrid.src.js). After such registration of the formatter you can use it in colModel as

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

因此,formatter属性的值将是 string (formatter: "myUrlFormatter")而不是函数(formatter: UrlFmatter).

So the value of formatter property will be string (formatter: "myUrlFormatter") instead of the function (formatter: UrlFmatter).

这篇关于使用AjaxCall为JQGrid动态加载列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 11:59