HTML代码:

  1. <div id="divList">
  2. <div class="toolbar">
  3. </div>
  4. <table id="list">
  5. </table>
  6. <div id="pager">
  7. </div>
  8. </div>
  1. <table id="tableCols" cellpadding="0" cellspacing="0">
  2. <tr>
  3. <td>
  4. <input id="checkAll" type="checkbox" />
  5. </td>
  6. <td class="tdText">
  7. 可选显示列:
  8. </td>
  9. <td>
  10. <input type="checkbox" text="发布周期" value="Period" />
  11. </td>
  12. <td class="tdText">
  13. 发布周期
  14. </td>
  15. <td>
  16. <input type="checkbox" text="客户执行金额" value="SellAmount" />
  17. </td>
  18. <td class="tdText">
  19. 客户执行金额
  20. </td>
  21. <td>
  22. <input type="checkbox" text="开户银行" value="OpenBank" />
  23. </td>
  24. <td class="tdText">
  25. 开户银行
  26. </td>
  27. <td>
  28. <input type="checkbox" text="银行账号" value="Account" />
  29. </td>
  30. <td class="tdText">
  31. 银行账号
  32. </td>
  33. <td>
  34. <input type="checkbox" text="联系人" value="Linkman" />
  35. </td>
  36. <td class="tdText">
  37. 联系人
  38. </td>
  39. <td>
  40. <input type="checkbox" text="电话" value="Phone" />
  41. </td>
  42. <td class="tdText">
  43. 电话
  44. </td>
  45. </tr>
  46. </table>

JS代码:

  1. // 查询方法
  2. function search() {
  3. //固定列
  4. var cols = ['Id', 'SupplierId', '年份', '合同编号', '项目名称', '供应商名称', '媒体点位', '合同时间', '上画时间', '合同总金额', '票据情况', '票据说明', '到票时间'];
  5. var rows = [{ name: 'Id', hidden: true },
  6. { name: 'SupplierId', hidden: true },
  7. { name: 'Year', sortable: false, width: 35, fixed: true },
  8. { name: 'ContractNo', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
  9. return "<a href='javascript:void(0)' onclick='view(\"" + r["Id"] + "\")' > " + v + "</a>";
  10. }
  11. },
  12. { name: 'ProjectName', sortable: false, width: 80, fixed: true },
  13. { name: 'SupplierName', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
  14. return "<a href='javascript:void(0)' onclick='viewSupplier(\"" + r["SupplierId"] + "\")' > " + v + "</a>";
  15. }
  16. },
  17. { name: 'Location', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
  18. return "<a href='javascript:void(0)' onclick='viewPurchase(\"" + r["Id"] + "\")' > " + v + "</a>";
  19. }
  20. },
  21. { name: 'DispContractStartTime', sortable: false, width: 80, fixed: true },
  22. { name: 'DispDrawingTime', sortable: false, width: 80, fixed: true },
  23. { name: 'SumAmount', sortable: false, width: 80, fixed: true, align: "right" },
  24. { name: 'InvoiceCondition', sortable: false, width: 60, fixed: true },
  25. { name: 'InvoiceDesc', sortable: false, width: 80, fixed: true },
  26. { name: 'ReceiveInvoiceTime', sortable: false, width: 80, fixed: true}];
  27.  
  28. //可选列
  29. $("#tableCols").find("input[text]:checked").each(function () {
  30. var checkbox = $(this);
  31. var colName = checkbox.val();
  32. var text = checkbox.attr("text");
  33. cols.push(text);
  34. rows.push({ name: colName, sortable: false, width: 80, fixed: true });
  35. });
  36.  
  37. //月份列
  38. cols.push("1月份");
  39. cols.push("2月份");
  40. cols.push("3月份");
  41. cols.push("4月份");
  42. cols.push("5月份");
  43. cols.push("6月份");
  44. cols.push("7月份");
  45. cols.push("8月份");
  46. cols.push("9月份");
  47. cols.push("10月份");
  48. cols.push("11月份");
  49. cols.push("12月份");
  50. rows.push({ name: "NotPay1", sortable: false, width: 80, fixed: true });
  51. rows.push({ name: "NotPay2", sortable: false, width: 80, fixed: true });
  52. rows.push({ name: "NotPay3", sortable: false, width: 80, fixed: true });
  53. rows.push({ name: "NotPay4", sortable: false, width: 80, fixed: true });
  54. rows.push({ name: "NotPay5", sortable: false, width: 80, fixed: true });
  55. rows.push({ name: "NotPay6", sortable: false, width: 80, fixed: true });
  56. rows.push({ name: "NotPay7", sortable: false, width: 80, fixed: true });
  57. rows.push({ name: "NotPay8", sortable: false, width: 80, fixed: true });
  58. rows.push({ name: "NotPay9", sortable: false, width: 80, fixed: true });
  59. rows.push({ name: "NotPay10", sortable: false, width: 80, fixed: true });
  60. rows.push({ name: "NotPay11", sortable: false, width: 80, fixed: true });
  61. rows.push({ name: "NotPay12", sortable: false, width: 80, fixed: true });
  62.  
  63. //列表
  64. $("#divList").html('<div class="toolbar"></div><table id="list"></table><div id="pager"></div>');
  65. $("#list").jqGrid({
  66. url: '#{GetSummaryIndexData}',
  67. serializeGridData: function (postData) {
  68. return Simpo.ui.jqGrid.serializeGridData(postData);
  69. },
  70. datatype: "json",
  71. colNames: cols,
  72. colModel: rows,
  73. rowNum: 10,
  74. rowList: [10, 20, 30],
  75. pager: '#pager',
  76. sortable: false,
  77. sortname: 'Id',
  78. sortorder: "desc",
  79. viewrecords: true,
  80. rownumbers: true,
  81. multiselect: true,
  82. height: 'auto',
  83. width: $(".adminMainContent").width(),
  84. loadComplete: function (xhr) {
  85. Simpo.ui.jqGrid.loadComplete("list", xhr);
  86.  
  87. //遍历数据行,将支付完毕的行颜色锁定
  88. $("#list").find("tr[id]").each(function () {
  89. var tr = $(this);
  90.  
  91. var noDataCount = 0;
  92. tr.find("td").each(function () {
  93. var td = $(this);
  94. if ($.trim(td.html()) == "NoData") {
  95. noDataCount++;
  96. }
  97. });
  98. if (noDataCount == 12) {
  99. tr.find("td").css("background-color", "#e6e6e6");
  100. }
  101. });
  102.  
  103. //还原显示所有月份列
  104. var titleTable = $("#list").parent().parent().parent().find("table:first");
  105. for (var i = 40; i >= 10; i--) {
  106. var th = titleTable.find("tr").find("th:eq(" + i + ")");
  107. if (th) th.css("display", "");
  108. }
  109. for (var i = 40; i >= 10; i--) {
  110. $("#list").find("tr").each(function () {
  111. var tr = $(this);
  112.  
  113. var td = tr.find("td:eq(" + i + ")");
  114. if (td) td.css("display", "");
  115. });
  116. }
  117.  
  118. //隐藏没有数据的月份列
  119. for (var i = 40; i >= 10; i--) {
  120. var del = true;
  121.  
  122. //遍历数据行的i列
  123. $("#list").find("tr[id]").each(function () {
  124. var tr = $(this);
  125.  
  126. var td = tr.find("td:eq(" + i + ")");
  127. if (td) {
  128. if ($.trim(td.html()) != "NoData") {
  129. del = false;
  130. }
  131. }
  132. else {
  133. del = false;
  134. }
  135. });
  136.  
  137. if (del) {
  138. //隐藏标题行的i列
  139. titleTable.find("tr").each(function () {
  140. var tr = $(this);
  141.  
  142. var th = tr.find("th:eq(" + i + ")");
  143. th.css("display", "none");
  144. });
  145.  
  146. //隐藏数据行的i列
  147. $("#list").find("tr").each(function () {
  148. var tr = $(this);
  149.  
  150. var td = tr.find("td:eq(" + i + ")");
  151. td.css("display", "none");
  152. });
  153. }
  154.  
  155. //遍历数据行的i列,删除NoData标记
  156. $("#list").find("tr[id]").each(function () {
  157. var tr = $(this);
  158.  
  159. var td = tr.find("td:eq(" + i + ")");
  160. if (td) {
  161. if ($.trim(td.html()) == "NoData") {
  162. td.html("&nbsp;");
  163. }
  164. }
  165. });
  166. }
  167. },
  168. onHeaderClick: function () {
  169. Simpo.ui.jqGrid.autoWidth("list"); // 自动宽度
  170. },
  171. loadError: function (xhr, status, error) {
  172. Simpo.ui.jqGrid.loadError("list", xhr, status, error);
  173. }
  174. });
  175. jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false }).jqGrid('sortableRows');
  176.  
  177. var postData = Simpo.ui.jqGrid.serializeGridData("list");
  178. jQuery("#list").jqGrid('setGridParam', { postData: postData, page: 1 }).trigger("reloadGrid");
  179. }

jqGrid动态列的更多相关文章

  1. jqGrid动态增加列,使用在根据条件筛选而出现不同的列的场景

    function GetGrid2() { var jqdata = [ { Encode:"20180100", FullName: "BYD", SpecT ...

  2. Dynamic CRM 2013学习笔记(二十六)报表设计:Reporting Service报表 动态参数、参数多选全选、动态列、动态显示行字体颜色

    上次介绍过CRM里开始报表的一些注意事项:Dynamic CRM 2013学习笔记(十五)报表入门.开发工具及注意事项,本文继续介绍报表里的一些动态效果:动态显示参数,参数是从数据库里查询出来的:参数 ...

  3. extjs动态树 动态grid 动态列

    由于项目需要做一个动态的extjs树.列等等,简而言之,就是一个都是动态的加载功能, 自己琢磨了半天,查各种资料,弄了将近两个星期,终于做出来了 首先,想看表结构,我的这个功能需要主从两张表来支持 代 ...

  4. displaytag 动态列实现

    这种动态列的实现方法来自displaytag-examples-1.2.war提供的示例中,实际上下载下来的zip文件中不仅有各种jar包,还有这个包含各种例子的war包,是学习displaytag的 ...

  5. Easy DataGrid 实现动态列、行

    Easy DataGrid 实现动态列.行 前端代码: <title>展示销售的实时数据</title> <script type="text/javascri ...

  6. 记React+.NetCore API实现动态列导出

    1.效果演示 2.用到的第三方类库 前端:React,Dva,Antd 后端:ASP.NET CORE,System.Linq.Dynamic.Core,EPPlus.Core 3.基本思路 第一:E ...

  7. datatable动态列处理,重绘表格(敲黑板,划重点!!!我肝了一天半才彻底弄懂这个东西,TAT)

    datatable动态列处理,重绘表格 前言:至于动态列的绘画,我前面博客已经写过了,就是动态列的配置问题,不懂的去我博客看下,今天要写的呢,就是你已经写了一个动态列在datatable,现在你想重新 ...

  8. jqGrid选择列控件向右拖拽超出边界处理

    jqGrid选择列控件向右拖拽超出边界处理 $("#tb_DeviceInfo").jqGrid('navButtonAdd', '#jqGridPager', {         ...

  9. [转]bootstrap table 动态列数

    原文地址:https://my.oschina.net/u/2356355/blog/1595563 据说bootstrap table非常好用,从入门教程中了解到它的以下主要功能: 由于固定表头意味 ...

随机推荐

  1. NCPC 2013: Dance Reconstruction

    题目大意 对一个初始矩阵进行置换操作,已知经K次置换后得到的矩阵为,求一组可能的. 样例解释 这里只选取第二组样例进行解释. 4 2 3 4 1 2 2 3 4 1 初始矩阵为,根据Sample Ou ...

  2. 使用sqlserver的游标功能来导数据的常见写法

    一定要自己试过才知道么? 你也没试过吃屎,你怎么知道屎不能吃,难道你试过啊...(没有愤怒的意思) ),),) declare cursor_data CURSOR FOR SELECT [UserN ...

  3. 命令行模式下 MYSQL导入导出.sql文件的方法

    一.MYSQL的命令行模式的设置:桌面->我的电脑->属性->环境变量->新建->PATH=“:path\mysql\bin;”其中path为MYSQL的安装路径.二.简 ...

  4. ASP.NET 4.0 potentially dangerous Request.Form value was detected

    A few days ago, while working on an ASP.NET 4.0 Web project, I got an issue. The issue was, when use ...

  5. dll return a string

    char g_szText[1024]; __declspec(dllexport) const char * __stdcall FuncName(const unsigned char *p) { ...

  6. OpenSSL Command-Line HOWTO

    OpenSSL Command-Line HOWTO The openssl application that ships with the OpenSSL libraries can perform ...

  7. [leetcode]Rotate Array

    in place交换 如果是k步,那么就是把后面k个放到前面了嘛. 我们先把整个数组reverse,然后把前面的reverse回来,再把后面的reverse回来 对于AB我们要通过reverse操作得 ...

  8. [转]c++流缓冲---rdbuf()

    C++标准库封装了一个缓冲区类streambuf,以供输入输出流对象使用.每个标准C++输出输出流对象都包含一个指向streambuf的指针,用 户可以通过调用rdbuf()成员函数获得该指针,从而直 ...

  9. 如何将 Cortana 与 Windows Phone 8.1 应用集成 ( Voice command - Natural language recognition )

    随着 Windows Phone 8.1 GDR1 + Cortana 中文版的发布,相信有很多用户或开发者都在调戏 Windows Phone 的语音私人助理 Cortana 吧,在世界杯的时候我亲 ...

  10. ux.form.field.SearchField 列表、树形菜单查询扩展

    //支持bind绑定store //列表搜索扩展,支持本地查询 //支持树形菜单本地一级菜单查询 Ext.define('ux.form.field.SearchField', { extend: ' ...