jqgrid formatter ajax,jqgrid setting custom formatter to dynamic column collection

I am using jqgrid. We are building a dashboard functionality with jquery. Different application just have to register respective application page and dashboard will render that page.To achieve this we are using jqgrid as one of the jquery plugin. Following is my code

var ph = '#' + placeHolder;

var _prevSort;

$.ajax({

url: dataUrl,

dataType: "json",

async: true,

success: function(json) {

pager = $('#' + pager);

if (json.showPager === "false") {

pager = eval(json.showPager);

}

dataUrl += "&jqSession=true";

$(ph).jqGrid({

url: dataUrl,

datatype: "json",

sortclass: "grid_sort",

colNames: JSON.parse(json.colNames),

colModel: JSON.parse(json.colModel),

forceFit: true,

rowNum: json.rowNum,

rowList: JSON.parse(json.rowList),

pager: pager,

sortname: json.sortName,

caption: json.caption,

viewrecords: true,

viewsortcols: true,

sortorder: json.sortOrder,

footerrow: summaryFooter,

userDataOnFooter: summaryFooter,

jsonReader: {

root: "rows",

row: "row",

repeatitems: false,

id: json.sortName

},

gridComplete: function() {

if (showFooter) {

$(ph).append("

" + json.footerRow + "");

}

if (json.additionalContent != null) {

$("#" + xContID).html(json.additionalContent);

}

$("ui-icon-asc").append("IMG");

var _rows = $(".jqgrow");

if (json.rows.length > 0) {

for (var i = 1; i < _rows.length; i += 1) {

_rows[i].attributes["class"].value = _rows[i].attributes["class"].value.replace(" ui-jqgrid-altrow", "");

if (i % 2 == 1) {

_rows[i].attributes["class"].value += " ui-jqgrid-altrow";

}

}

var gMaxHeight = getGridMaxHeight();

var gHeight = ($(ph + " tr").length + 1) * ($($(".jqgrow") [0]).height());

if (gHeight <= gMaxHeight) {

$(ph).parent().height(gHeight);

}

else {

$(ph).parent().height(gMaxHeight);

}

}

else {

$(ph).prepend("

" + gridNoDataMsg + "");

$(ph).parent().height(60);

}

},

onSortCol: function(index, iCol, sortorder) {

dataUrl = dataUrl.replace("&jqSession=true", "");

$(ph).jqGrid().setGridParam({ url: dataUrl }).trigger("reloadGrid");

var _colName = "#jqgh_" + index;

// $(_prevSort).parent().removeClass("ui-jqgrid-sorted");

// $(_prevSort).parent().addClass("ui-state-default");

// $(_colName).parent().addClass("ui-jqgrid-sorted");

// $(_colName).parent().removeClass("ui-state-default");

_prevSort = _colName;

var _rows = $(".jqgrow");

for (var i = 1; i < _rows.length; i += 1) {

_rows[i].attributes["class"].value = _rows[i].attributes["class"].value.replace(" ui-jqgrid-altrow", "");

if (i % 2 == 1) {

_rows[i].attributes["class"].value += " ui-jqgrid-altrow";

}

}

}

}).navGrid('#' + pager, { search: false, sort: false, edit: false, add: false, del: false, refresh: false }); // end of grid

$("#" + loadid).empty();

gGridIds[gGridIds.length] = placeHolder;

SetGridSizes();

},

error: function() {

$("#" + loadid).html(loadingErr);

}

});

As you can see from the code i am getting column collection dynamically(Appication page which i am calling will give me JSON in the response and will have colNames collection in it. Evrything is working fine but, only issue is coming when we are trying to apply custom formatter to column. This issue comes only when we are dynamically assign "colModel" to jqgrid.

Appreciate help

Thanks in advance

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值