jqgrid 用代码添加列数据

jqgrid 用代码添加列数据,第1张

在初始化jqgrid的时候定义如下两个function

onCellSelect:function(rowid,col,cellcontent){

 var selectthis = $(this)

 if(col===5 && cellcontent == "暂时不能 *** 作"){

  selectthis.setCell(rowid,5,'可以 *** 作')

 }

},

afterInsertRow: function(rowid, aData){

 var selectthis = $(this)

 var modify = true

 for(var i=0i<6i++){

  var tmepcontens = selectthis.getCell(rowid,i)

  if(tmepcontens == ""){

   modify = false

   break

  }

 }

 if(!modify){

  selectthis.setCell(rowid,5,'暂时不能 *** 作')

 }

}

这里只提供实现思路:

jqgrid中的colNames,后面是一个表头列名数组,此数组可以从调用这个grid的函数参数中传进去,意味着,可以写一个数组,存一部分固定列,然后通过ajax请求去数据库中查出自定义列,放到固定列的后面。这样我们就拼装起了这个表头数组。

jqGrid中的colModel字段的长度必须和colNames一样,并且也是可变的。意味着这个也需要从参数中传过来,也需要在js中拼装这样一个对象数组。

至于自定义数据对应显示。这个在js里面的接受的属性叫jsonReader。用root来接受Action中返回的拼装Json字符串

在后台Action中,需要将固定列和对应的属性值,自定义列和对应的属性值。使用Gson,拼装成Json数据对象,然后传到前台。

在JS中JqGrid的代码加上

jsonReader:{

root:"gridModel",

records:"record",

repeatitems:false

},

后台返回JSON数据:{"gridModel":[

{"seihin_bango":"值","seihin_meisho":"值","kishu":“值”,"buhin_bango":"值",.....},

{"seihin_bango":"值","seihin_meisho":"值","kishu":“值”,"buhin_bango":"值",.....},

{"seihin_bango":"值","seihin_meisho":"值","kishu":“值”,"buhin_bango":"值",.....},

....

],"rows":15,"record":95,"page":1,"total":7,"sord":null,"sidx":null,"search":null}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11502865.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存