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

下面直接上代码

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. hdu1281二分图匹配

    小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的"车",并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放, ...

  2. 分针网—每日分享:HTML解析原理

    标准的web前端工程师需要知道 ◎浏览器(或者相应播放器)的渲染/重绘原理   这我得加把劲了.我还真的说的不是很清楚,我就G下,结果不是很多,找到了有一个,就记下来了...   以下部分来自hand ...

  3. 分针网——每日分享: jquery选择器的用法

    jQuery选择器是jQuery库的一大特色,用这些选择器不但可以省去繁琐的JavaScript 书写方式,还可以节省时间和效率,正是有这些jQuery选择器,才让我们更容易的操作JavaScript ...

  4. 原生JS-----论数据类型检测

    常见的数据类型检测的方法: 一.最为基础的typeof 二.不可不知的instanceof 三.比instanceof更好的constructor 四.检测值或者表达式的结果是否为NaN 五.易用的j ...

  5. JS第二弹:用Jquery组装html标签,输出到页面

    用Ajax从服务端获取数据,遍历到表格中(其实将表格替换了),中间发现不能为新增的元素绑定事件,原来是没有将其作为JQ对象

  6. 刚由pc端做移动端的感受

    最近新调到一个项目,由原来的pc端,调到移动端,一切都是那么的不一样,在得知即将调到移动端的时候,听说我们的技术要用到vue,Aladdin,还有es6,有点懵... 我做了以下准备工作: 1,买了本 ...

  7. 属于自己的MES(一)概念

    什么叫MES(生产制造执行系统)? 从几个方面来简单说下: 1.定位 没有MES前的工厂生产模式,公司MRP系统与生产现场之间透过人为方式沟通,使生产现场如同黑箱作业,无法掌握实时正确信息. MES的 ...

  8. hdu1198 Farm Irrigation 并查集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1198 简单并查集 分别合并竖直方向和水平方向即可 代码: #include<iostream&g ...

  9. 【2017-05-17】WebForm

    ASP.NET分为:ASP.NET WebForm和ASP.NET MVC 运行机制:C/S(客户端应用程序)代码在客户端执行,仅仅去服务器上的数据库存取数据 B/S(网站应用程序)程序代码在服务器上 ...

  10. ReentrantLock深入学习

    ReentrankLock  分为 非公平锁及公平锁 首先我们看一下它里面有哪些属性: private final Sync sync;Sync 这个类是 ReentrantLock的 一个静态内部类 ...