HTML代码:

<div id="divList">
<div class="toolbar">
</div>
<table id="list">
</table>
<div id="pager">
</div>
</div>
<table id="tableCols" cellpadding="0" cellspacing="0">
<tr>
<td>
<input id="checkAll" type="checkbox" />
</td>
<td class="tdText">
可选显示列:
</td>
<td>
<input type="checkbox" text="发布周期" value="Period" />
</td>
<td class="tdText">
发布周期
</td>
<td>
<input type="checkbox" text="客户执行金额" value="SellAmount" />
</td>
<td class="tdText">
客户执行金额
</td>
<td>
<input type="checkbox" text="开户银行" value="OpenBank" />
</td>
<td class="tdText">
开户银行
</td>
<td>
<input type="checkbox" text="银行账号" value="Account" />
</td>
<td class="tdText">
银行账号
</td>
<td>
<input type="checkbox" text="联系人" value="Linkman" />
</td>
<td class="tdText">
联系人
</td>
<td>
<input type="checkbox" text="电话" value="Phone" />
</td>
<td class="tdText">
电话
</td>
</tr>
</table>

JS代码:

// 查询方法
function search() {
//固定列
var cols = ['Id', 'SupplierId', '年份', '合同编号', '项目名称', '供应商名称', '媒体点位', '合同时间', '上画时间', '合同总金额', '票据情况', '票据说明', '到票时间'];
var rows = [{ name: 'Id', hidden: true },
{ name: 'SupplierId', hidden: true },
{ name: 'Year', sortable: false, width: 35, fixed: true },
{ name: 'ContractNo', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
return "<a href='javascript:void(0)' onclick='view(\"" + r["Id"] + "\")' > " + v + "</a>";
}
},
{ name: 'ProjectName', sortable: false, width: 80, fixed: true },
{ name: 'SupplierName', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
return "<a href='javascript:void(0)' onclick='viewSupplier(\"" + r["SupplierId"] + "\")' > " + v + "</a>";
}
},
{ name: 'Location', sortable: false, width: 80, fixed: true, formatter: function (v, o, r) {
return "<a href='javascript:void(0)' onclick='viewPurchase(\"" + r["Id"] + "\")' > " + v + "</a>";
}
},
{ name: 'DispContractStartTime', sortable: false, width: 80, fixed: true },
{ name: 'DispDrawingTime', sortable: false, width: 80, fixed: true },
{ name: 'SumAmount', sortable: false, width: 80, fixed: true, align: "right" },
{ name: 'InvoiceCondition', sortable: false, width: 60, fixed: true },
{ name: 'InvoiceDesc', sortable: false, width: 80, fixed: true },
{ name: 'ReceiveInvoiceTime', sortable: false, width: 80, fixed: true}]; //可选列
$("#tableCols").find("input[text]:checked").each(function () {
var checkbox = $(this);
var colName = checkbox.val();
var text = checkbox.attr("text");
cols.push(text);
rows.push({ name: colName, sortable: false, width: 80, fixed: true });
}); //月份列
cols.push("1月份");
cols.push("2月份");
cols.push("3月份");
cols.push("4月份");
cols.push("5月份");
cols.push("6月份");
cols.push("7月份");
cols.push("8月份");
cols.push("9月份");
cols.push("10月份");
cols.push("11月份");
cols.push("12月份");
rows.push({ name: "NotPay1", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay2", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay3", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay4", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay5", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay6", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay7", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay8", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay9", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay10", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay11", sortable: false, width: 80, fixed: true });
rows.push({ name: "NotPay12", sortable: false, width: 80, fixed: true }); //列表
$("#divList").html('<div class="toolbar"></div><table id="list"></table><div id="pager"></div>');
$("#list").jqGrid({
url: '#{GetSummaryIndexData}',
serializeGridData: function (postData) {
return Simpo.ui.jqGrid.serializeGridData(postData);
},
datatype: "json",
colNames: cols,
colModel: rows,
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
sortable: false,
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
rownumbers: true,
multiselect: true,
height: 'auto',
width: $(".adminMainContent").width(),
loadComplete: function (xhr) {
Simpo.ui.jqGrid.loadComplete("list", xhr); //遍历数据行,将支付完毕的行颜色锁定
$("#list").find("tr[id]").each(function () {
var tr = $(this); var noDataCount = 0;
tr.find("td").each(function () {
var td = $(this);
if ($.trim(td.html()) == "NoData") {
noDataCount++;
}
});
if (noDataCount == 12) {
tr.find("td").css("background-color", "#e6e6e6");
}
}); //还原显示所有月份列
var titleTable = $("#list").parent().parent().parent().find("table:first");
for (var i = 40; i >= 10; i--) {
var th = titleTable.find("tr").find("th:eq(" + i + ")");
if (th) th.css("display", "");
}
for (var i = 40; i >= 10; i--) {
$("#list").find("tr").each(function () {
var tr = $(this); var td = tr.find("td:eq(" + i + ")");
if (td) td.css("display", "");
});
} //隐藏没有数据的月份列
for (var i = 40; i >= 10; i--) {
var del = true; //遍历数据行的i列
$("#list").find("tr[id]").each(function () {
var tr = $(this); var td = tr.find("td:eq(" + i + ")");
if (td) {
if ($.trim(td.html()) != "NoData") {
del = false;
}
}
else {
del = false;
}
}); if (del) {
//隐藏标题行的i列
titleTable.find("tr").each(function () {
var tr = $(this); var th = tr.find("th:eq(" + i + ")");
th.css("display", "none");
}); //隐藏数据行的i列
$("#list").find("tr").each(function () {
var tr = $(this); var td = tr.find("td:eq(" + i + ")");
td.css("display", "none");
});
} //遍历数据行的i列,删除NoData标记
$("#list").find("tr[id]").each(function () {
var tr = $(this); var td = tr.find("td:eq(" + i + ")");
if (td) {
if ($.trim(td.html()) == "NoData") {
td.html("&nbsp;");
}
}
});
}
},
onHeaderClick: function () {
Simpo.ui.jqGrid.autoWidth("list"); // 自动宽度
},
loadError: function (xhr, status, error) {
Simpo.ui.jqGrid.loadError("list", xhr, status, error);
}
});
jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false }).jqGrid('sortableRows'); var postData = Simpo.ui.jqGrid.serializeGridData("list");
jQuery("#list").jqGrid('setGridParam', { postData: postData, page: 1 }).trigger("reloadGrid");
}

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. Oracle 12c

    Common User vs. Local User – 12c Edition http://dbasolved.com/2013/06/29/common-user-vs-local-user-1 ...

  2. 开源Launcher - Wox 出炉了

    Wox 是一款免费开源的信息快速获取软件.她的创作灵感来自于Mac上Alfred和Window上的Launchy. 目前Wox托管在Github (http://www.github.com/qian ...

  3. android 渐变展示启动屏

    启动界面Splash Screen在应用程序是很常用的,往往在启动界面中显示产品Logo.公司Logo或者开发者信息,如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段 ...

  4. 在 Excel 中使用正则表达式进行查找与替换

    在 Excel 中,使用 Alt+F11 快捷键打开 VBA 项目窗口,在左侧的工作表名称上点右键,选择查看代码,即可出出现右侧的代码编辑窗口 在代码窗口中输入以下代码: Private Sub Re ...

  5. GitHub上排名前100的Android开源库介绍(来自github)

    本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍,至于排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果,然后过滤了 ...

  6. 游戏服务器ID生成器组件

    游戏服务器程序中,经常需要生成全局的唯一ID号,这个功能很常用,本文将介绍一种通用ID生成组件.游戏服务器程序中使用此组件的场景有: 创建角色时,为其分配唯一ID 创建物品时,每个物品需要唯一ID 创 ...

  7. iOS 企业证书发布app 流程

    企业发布app的 过程比app store 发布的简单多了,没那么多的要求,哈 但是整个工程的要求还是一样,比如各种像素的icon啊 命名规范啊等等. 下面是具体的流程 1.修改你的 bundle i ...

  8. JavaScript 32位整型无符号操作

    在 JavaScript 中,所有整数字变量默认都是有符号整数,这意味着什么呢? 有符号整数使用 31 位表示整数的数值,用第 32 位表示整数的符号,0 表示正数,1 表示负数. 数值范围从 -2^ ...

  9. STM32 flash 内存分布介绍

    摘要: 本文以STM32F103RBT6为例介绍了片上Flash(Embedded Flash)若干问题,包括Flash大小(内存映射).块大小.页面大小.寄存器.这些知识,有利于写Flash驱动. ...

  10. IOS APP上下黑边问题

    网上的一种是一个问题, 更换launchImage 后 APP在iPhone5下出现黑边. 原因是:我将Jpg(640*1136)的图片 强制改为Png(640*1136),导致APP出现黑边.