最近碰到一个需求,需要提供一个弹出页面选择列表页面需要显示的列,页面确认之后需要修改列表页面显示的表格,导出的数据也需要同步变化。

下面直接上代码

1.设置需要显示的列columus为全局对象,用于子页面调用

var columns = [
    [
        { field: "HouseNo", title: "房屋编号", width: 80, align: "center" },
        { field: "HouseDoorplate", title: "现房屋门牌", width: 80, align: "center" },
        { field: "RentRange", title: "租赁范围", width: 80, align: "center" },
        { field: "ContractNo", title: "合同编号", width: 80, align: "center" },
        { field: "Name", title: "承租人", width: 80, align: "center" },
        { field: "HouseManageName", title: "工作站名称", width: 80, align: "center" },
        { field: "HousekeepName", title: "房管员", width: 80, align: "center" },
        { field: "PropertyName", title: "产权属性", width: 80, align: "center" },
        { field: "BaseRent", title: "租金基数", width: 80, align: "center" },
        { field: "CreditCardName", title: "减免情况", width: 80, align: "center" },
        { field: "ReduceMoney", title: "减免金额", width: 80, align: "center" },
        { field: "CollectMoney", title: "应收租金", width: 80, align: "center" },
        { field: "BuildArea", title: "建筑面积", width: 80, align: "center" },
        { field: "MetRentArea", title: "计租面积", width: 80, align: "center" },
        { field: "ContactNumber", title: "联系电话", width: 80, align: "center" },
        { field: "UsePropertyName", title: "使用性质", width: 80, align: "center" },
        { field: "TotalFloors", title: "总层数", width: 80, align: "center" },
        { field: "CompletYear", title: "建成年份", width: 80, align: "center" },
        { field: "BuildStructureName", title: "建筑结构", width: 80, align: "center" },
        { field: "IsTaoName", title: "是否成套住宅", width: 80, align: "center" }
    ]
];

2.页面初始化方法

var StatisticalRentReport = {
Initialize: function (columns) {
        $("#StatisticalRentReportDataGrid").datagrid({
            columns: columns,
            checkOnSelect: true,
            height: '500',
            idField: "id",
            striped: true,
            singleSelect: true,
            fitColumns: false,
            fit: false,
            loadMsg: false,
            nowrap: false,
            rownumbers: true, //行号
            pagination: true, //分页控件
            pageSize: 10,
            pageList: [10, 50, 100, 500, 1000, 2000, 10000],
            showFooter: true,
            onLoadSuccess: function (data) {
                $(this).datagrid('doCellTip', { 'max-width': '400px', 'delay': 500 });
                $(this).datagrid("clearSelections").datagrid("clearChecked");
            },
            loader: function (param, success, error) {
                $.ajax({
                    type: "POST",
                    url: "/Home/GetData",
                    contentType: "application/json",
                    data: null
                }).done(function (data) {
                    console.log(data);
                    if (data) {
                        success(data);
                    } else {
                        error();
                    }
                }).fail(function () {

                });
            }
        });
        for (var i = 0; i < $(".easyui-textbox").length; i++) {
            $("#" + $('.easyui-textbox').eq(i)[0].id + "").textbox({
                inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
                    keyup: function (event) {
                        if (event.keyCode === 13) {
                            StatisticalRentReport.Select();
                        }
                    }
                })
            });
        };
    },
};
$(function() {
    StatisticalRentReport.Initialize(columns);
})

3.弹出列属性设置页面,这里会遍历所有表格数据,传递名称用于列隐藏显示匹配

//导入房屋完损状况
    ColumnProperties: function () {
        var html = "";
        for (var i = 0; i < columns[0].length; i++) {
            if (columns[0][i].hidden !== true) {
                html += columns[0][i].title + ",";
            }
        }
        dialog = ezg.modalDialog({
            width: 650,
            height: 370,
            title: '房屋查询报表列属性设置',
            url: '/Report/ColumnProperties?Column=' + html
        });
    },

4.初始化列属性选中状态

$(function () {
    var columnId = topevery.getQuery('Column');
    var columns1 =  columnId.split(',');
    var obj = $("input[name='column']");
    for (var i = 0; i < obj.length; i++) {
        for (var j = 0; j < columns1.length; j++) {
            if (obj[i].value === columns1[j]) {
                $(obj[i]).attr('checked', 'checked');///初始化显示列表已经显示的列数据为选择
            }
        }
    }
})

5.保存需要显示的列数据

var ColumnProperties= {
    Save: function () {
        var obj = $("input[name='column']:checked");
        var columns = parent.columns[0].concat();//深copy一个对象用于遍历保存需要隐藏的列数据
        var columns1 = parent.columns[0].concat();//深copy一个对象用于遍历保存需要显示的列数据
        for (var i = 0; i < obj.length; i++) {
            for (var j = 0; j < columns.length; j++) {
                if (obj[i].value === columns[j].title) {
                    columns.splice(j, 1);//删除需要显示的列数据
                }
            }
        }
        for (var k = 0; k < columns1.length; k++) {
            columns1[k].hidden = false;//初始化所有列数据为显示,如果不初始化,隐藏掉的列就无法再显示了
        }
        for (var f = 0; f < columns1.length; f++) {
            for (var h = 0; h < columns.length; h++) {
                if (columns1[f].title === columns[h].title) {
                    columns1[f].hidden = true;//设置需要隐藏列的hidden属性为true
                }
            }
        }
        var object = new Array();
        object[0] = columns1;
        parent.StatisticalRentReport.Initialize(object);//重新构造datagrid表格
        parent.dialog.dialog('close');//关闭弹出框口
    }
}

6.导出数据设置需要导出的列

RentExp: function () {
        var html = "";
        for (var i = 0; i < columns[0].length; i++) {
            if (columns[0][i].hidden !== true) {
                html += columns[0][i].title + ",";
            }
        }
        window.location.href = "/Report/StatisticalRentReportExpAsync?Column=" + html;
    }

7.设置需要导出的表头属性

 if (input.Column.Contains("房屋编号"))
            {
                dt.Columns.Add("房屋编号", typeof(string));
            }
            if (input.Column.Contains("现房屋门牌"))
            {
                dt.Columns.Add("现房屋门牌", typeof(string));
            }
            if (input.Column.Contains("租赁范围"))
            {
                dt.Columns.Add("租赁范围", typeof(string));
            }
            if (input.Column.Contains("合同编号"))
            {
                dt.Columns.Add("合同编号", typeof(string));
            }
            if (input.Column.Contains("承租人"))
            {
                dt.Columns.Add("承租人", typeof(string));
            }
            if (input.Column.Contains("工作站名称"))
            {
                dt.Columns.Add("工作站名称", typeof(string));
            }
            if (input.Column.Contains("房管员"))
            {
                dt.Columns.Add("房管员", typeof(string));
            }
            if (input.Column.Contains("产权属性"))
            {
                dt.Columns.Add("产权属性", typeof(string));
            }
            if (input.Column.Contains("租金基数"))
            {
                dt.Columns.Add("租金基数", typeof(string));
            }
            if (input.Column.Contains("减免情况"))
            {
                dt.Columns.Add("减免情况", typeof(string));
            }
            if (input.Column.Contains("减免金额"))
            {
                dt.Columns.Add("减免金额", typeof(string));
            }
            if (input.Column.Contains("应收租金"))
            {
                dt.Columns.Add("应收租金", typeof(string));
            }
            if (input.Column.Contains("建筑面积"))
            {
                dt.Columns.Add("建筑面积", typeof(string));
            }
            if (input.Column.Contains("计租面积"))
            {
                dt.Columns.Add("计租面积", typeof(string));
            }
            if (input.Column.Contains("联系电话"))
            {
                dt.Columns.Add("联系电话", typeof(string));
            }
            if (input.Column.Contains("使用性质"))
            {
                dt.Columns.Add("使用性质", typeof(string));
            }
            if (input.Column.Contains("总层数"))
            {
                dt.Columns.Add("总层数", typeof(string));
            }
            if (input.Column.Contains("建成年份"))
            {
                dt.Columns.Add("建成年份", typeof(string));
            }
            if (input.Column.Contains("建筑结构"))
            {
                dt.Columns.Add("建筑结构", typeof(string));
            }
            if (input.Column.Contains("是否成套住宅"))
            {
                dt.Columns.Add("是否成套住宅", typeof(string));
            }

8.设置需要导出的列对应的导出数据

 foreach (var rentIncomeReportEx in list)
            {
                DataRow row = dt.NewRow();
                var rowlist = input.Column.Split(',');
                ; i < rowlist.Length; i++)
                {
                    ;
                    if (input.Column.Contains("房屋编号"))
                    {
                        row[j] = rentIncomeReportEx.HouseNo;
                        j++;
                    }
                    if (input.Column.Contains("现房屋门牌"))
                    {
                        row[j] = rentIncomeReportEx.HouseDoorplate;
                        j++;
                    }
                    if (input.Column.Contains("租赁范围"))
                    {
                        row[j] = rentIncomeReportEx.RentRange;
                        j++;
                    }
                    if (input.Column.Contains("合同编号"))
                    {
                        row[j] = rentIncomeReportEx.ContractNo;
                        j++;
                    }
                    if (input.Column.Contains("承租人"))
                    {
                        row[j] = rentIncomeReportEx.Name;
                        j++;
                    }
                    if (input.Column.Contains("工作站名称"))
                    {
                        row[j] = rentIncomeReportEx.HouseManageName;
                        j++;
                    }
                    if (input.Column.Contains("房管员"))
                    {
                        row[j] = rentIncomeReportEx.HousekeepName;
                        j++;
                    }
                    if (input.Column.Contains("产权属性"))
                    {
                        row[j] = rentIncomeReportEx.PropertyName;
                        j++;
                    }
                    if (input.Column.Contains("租金基数"))
                    {
                        row[j] = rentIncomeReportEx.BaseRent;
                        j++;
                    }
                    if (input.Column.Contains("减免情况"))
                    {
                        row[j] = rentIncomeReportEx.CreditCardName;
                        j++;
                    }
                    if (input.Column.Contains("减免金额"))
                    {
                        row[j] = rentIncomeReportEx.ReduceMoney;
                        j++;
                    }
                    if (input.Column.Contains("应收租金"))
                    {
                        row[j] = rentIncomeReportEx.CollectMoney;
                        j++;
                    }
                    if (input.Column.Contains("建筑面积"))
                    {
                        row[j] = rentIncomeReportEx.BuildArea;
                        j++;
                    }
                    if (input.Column.Contains("计租面积"))
                    {
                        row[j] = rentIncomeReportEx.MetRentArea;
                        j++;
                    }
                    if (input.Column.Contains("联系电话"))
                    {
                        row[j] = rentIncomeReportEx.ContactNumber;
                        j++;
                    }
                    if (input.Column.Contains("使用性质"))
                    {
                        row[j] = rentIncomeReportEx.UsePropertyName;
                        j++;
                    }
                    if (input.Column.Contains("总层数"))
                    {
                        row[j] = rentIncomeReportEx.TotalFloors;
                        j++;
                    }
                    if (input.Column.Contains("建成年份"))
                    {
                        row[j] = rentIncomeReportEx.CompletYear;
                        j++;
                    }
                    if (input.Column.Contains("建筑结构"))
                    {
                        row[j] = rentIncomeReportEx.BuildStructureName;
                        j++;
                    }
                    if (input.Column.Contains("是否成套住宅"))
                    {
                        row[j] = rentIncomeReportEx.IsTaoName;
                    }
                }
                dt.Rows.Add(row);
            }

            ds.Tables.Add(dt);

具体效果请查看Dome实例

Dome链接http://pan.baidu.com/s/1o87GEpG  提取码 i8tr

Easyui设置动态表格,动态导出数据实例,附Dome的更多相关文章

  1. Easyui设置动态表格,动态导出数据实例,附Demo

    最近开发的过程中碰到一个客户提出的需求,一个指定的页面导出需要提供一个弹出页面选择列表页面需要显示的列,页面确认之后需要修改列表页面显示的表格,导出的数据也需要同步变化. 总结一下可以称为一个列表数据 ...

  2. jQuery的下面是动态表格动态表单中的HTML代码

    动态表格动态表单中的Jquery代码 <script type="text/javascript" src="/include/jquery/jquery-1.1. ...

  3. Java实现PDF和Excel生成和数据动态插入以及导出

    一.序言 Excel.PDF的导出.导入是我们工作中经常遇到的一个问题,刚好今天公司业务遇到了这个问题,顺便记个笔记以防下次遇到相同的问题而束手无策. 公司有这么两个需求: 需求一.给了一个表单,让把 ...

  4. jquery表格动态增删改及取数据绑定数据完整方案

    一 前言 上一篇Jquery遮罩插件,想罩哪就罩哪! 结尾的预告终于来了. 近期参与了一个针对内部员工个人信息收集的系统,其中有一个需求是在填写各个相关信息时,需要能动态的增加行当时公司有自己的解决方 ...

  5. 基于layui,Jquery 表格动态编辑 设置 编辑值为 int 或者 double 类型及默认值

    首先先推荐大家在看这篇笔记时,阅读过我写的这篇 Layui表格编辑[不依赖Layui的动态table加载] 阅读过上面那篇笔记之后呢,才能更好的理解我现在所要说的这个东西 接下来废话不多说,上代码. ...

  6. 在页面上绘制一张表格,使用 DOM 节点的动态添加和删除向表格中插入数据,点击表格每行后的“删除”超链接

    查看本章节 查看作业目录 需求说明: 在页面上绘制一张表格,使用 DOM 节点的动态添加和删除向表格中插入数据,点击表格每行后的"删除"超链接,使用 DOM 节点的删除操作将对应的 ...

  7. easyui datagrid 可过滤行的数据表格 导出

    //过滤栏表格导出数据                  /* xukf                 * id datagrid id                 * url Action 路 ...

  8. 数据的动态合并和导出至EXCEL

    最近一段时间都在处理数据的动态合并和导出EXCEL的问题,写个demo记录下,希望和我碰到同样问题的博友可以顺利解决:后面会提供demo下载链接. (VS2012,ASP.NET) 一.主要解决以下问 ...

  9. ajax异步获取数据后动态向表格中添加数据(行)

    因为某些原因,项目中突然需要做自己做个ajax异步获取数据后动态向表格中添加数据的页面,网上找了半天都没有 看到现成的,决定自己写个例子 1.HTML页面 <!doctype html> ...

随机推荐

  1. IOS中的UIScrollView

    要引用UIScrollView 首先要遵循UIScrollViewDelegate协议 然后重写 //1.拖拽方法 -(void)scrollViewDidScroll:(UIScrollView * ...

  2. redis多数据库操作

    redis下,数据库是由一个整数索引标识,而不是由一个数据库名称.默认情况下,一个客户端连接到数据库0. redis配置文件中下面的参数来控制数据库总数: databases 16   [root@M ...

  3. Linux下链接数据库图形化工具

    (一).Linux环境下mysql的安装.SQL操作 Linux下安装MySQL (rmp --help) 基本步骤:上传软件->检查当前Linux环境是否已经安装,如发现系统自带的,先卸载-& ...

  4. 反序列py脚本分享(原创)

    代码如下: #!/usr/bin/env python # coding=utf-8 import socket import sys import requests import base64 im ...

  5. PHP中的运算符

    一.算术运算符   运算符 名称 描述 实例 结果 x + y 加 x 和 y 的和 2 + 2 4 x - y 减 x 和 y 的差 5 - 2 3 x * y 乘 x 和 y 的积 5 * 2 1 ...

  6. ArrayList源码解析(一)

    源码解析系列主要对Java的源码进行详细的说明,由于水平有限,难免出现错误或描述不准确的地方,还请大家指出. 1.位置 ArrayList位于java.util包中. package java.uti ...

  7. nginx配置优化+负载均衡+动静分离详解

    nginx配置如下: #指定nginx进程运行用户以及用户组user www www;#nginx要开启的进程数为8worker_processes 8;#全局错误日志文件#debug输出日志最为详细 ...

  8. [原创]Nexus5 源码下载、编译、真机烧录过程记录

    asop使用清华镜像源https://mirror.tuna.tsinghua.edu.cn/help/AOSP/ 一开始使用每月初始化包的方式因为无法搞定版本的问题,没能通过编译,无奈,老老实实一点 ...

  9. Node.js入门第一天

    一.Node.js简介 1.1 简介 V8引擎本身就是用于Chrome浏览器的JS解释部分,但是Ryan Dahl这哥们,鬼才般的,把这个V8搬到了服务器上,用于做服务器的软件. Node.js是一个 ...

  10. 关于JS的return false

    之前真的不知道JS里的return false 还能跳出事件. 今天在修改BUG的时候,用到了这个,就去查了一下,为了加深记忆在此处做个总结. retrun true: 返回正确的处理结果. retu ...