首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问EasyuI $.post怎么带上页面参数

2014-01-14 
请教EasyuI $.post如何带上页面参数function TableInit() {$(#dg).datagrid({toolbar: #toolBar,title

请教EasyuI $.post如何带上页面参数

        function TableInit() {

            $('#dg').datagrid({
                toolbar: "#toolBar",
                title: "报表查询",
                loadMsg: '正在加载信息...',
                iconCls: "icon-grid",
                singleSelect: true,
                striped: true,
                fitColumns: true,
                singleSelect: true,
                pagination: true,
                rownumbers: false,
                pageSize: 15,
                pageList: [15, 20, 30, 40, 50],
                columns: [[]],
                onLoadError: function () {
                    $.messager.alert('查询出错', '加载数据出错');
                },
                onLoadSuccess: function (data) {
                    if (data.rows.length == 0) {
                        var body = $(this).data().datagrid.dc.body2;
                        body.find('table tbody').append('<tr><td width="' + body.width() + '" style="height: 25px; text-align: center; color:Red;">没有数据</td></tr>');
                    }

                }
            });
        }

        function Search() {

            if (!DateCheck()) {
                return;
            }    

            var businessDateStart = GetSelectedBusinessDate("#businessYearStart", "#businessMonthStart");
            var businessDateEnd = GetSelectedBusinessDate("#businessYearEnd", "#businessMonthEnd");
            var businessType = $('input:radio[name=BusinessType]:checked').val();

            var url = 'Process/FileExportHandler.ashx?ProcessType=QueryReport&BusinessDateStart=' + businessDateStart + '&BusinessDateEnd=' + businessDateEnd + '&BusinessType=' + businessType + '&t=' + new Date();
            $('#dg').datagrid({ url: url });    
        }


对于一般的查询,我都是上面的方式,没问题。
但是对于一些查询的列不确定的数据(动态列),就只能改为下面的方式(因为返回的列数据是放在
data.columns)中的。

            $.post('Process/FileExportHandler.ashx', { ProcessType: 'QueryReport', BusinessDateStart: businessDateStart, BusinessDateEnd: businessDateEnd, BusinessType: businessType },
             function (data) {
                 $('#dg').datagrid({ columns: [data.columns] }).datagrid("loadData", data);
              }, 'json');     
可是上面存在一个问题,就是$.post提交时,page与rows是没有带过去的,即在后台获取不到下面数据
                    //int pageNumber = int.Parse(context.Request["page"]);


                    //int pageSize = int.Parse(context.Request["rows"]);       


[解决办法]
你这个是自定义获取数据,都没有设置url,当然不会处理你的分页

columns要动态获取你可以先发送ajax获取到column的内容后再构造grid,加上url配置

你要动态附加其他参数可以使用onBeforeLoad事件,参数为param,修改param参数增加你的附加数据就行了,这些附加的数据会一起发送到服务器

     $(function () {
            TableInit();       
        });
 
 
        function TableInit() {
            $.post('Process/FileExportHandler.ashx', function (data) {//动态页只需要返回column就行了,数据不需要了
                $('#dg').datagrid({
                    toolbar: "#toolBar",
                    title: "查询",
                    loadMsg: '正在加载信息...',
                    iconCls: "icon-grid",
                    singleSelect: true,
                    striped: true,
                    fitColumns: true,
                    singleSelect: true,
                    pagination: true,
                    rownumbers: false,
                    pageSize: 15,
                    pageList: [15, 20, 30, 40, 50],
                    url: 'xxxxxxxxx', ////
                    columns: [data.columns],
                    onBeforeLoad: function (param) {

                        var businessDateStart = GetSelectedBusinessDate("#businessYearStart", "#businessMonthStart");
                        var businessDateEnd = GetSelectedBusinessDate("#businessYearEnd", "#businessMonthEnd");
                        var businessType = $('input:radio[name=BusinessType]:checked').val();
                        var gridOpts = $('#dg').datagrid('getPager').data("pagination").options;
                        param.ProcessType = 'QueryReport';
                        param.BusinessDateStart = businessDateStart;
                        param.BusinessDateEnd = businessDateEnd;
                        param.BusinessType = businessType


                        param.page = gridOpts.pageNumber
                        param.rows = gridOpts.pageSize
                    }
                });
            });
        }


        function Search() {

            var businessDateStart = GetSelectedBusinessDate("#businessYearStart", "#businessMonthStart");
            var businessDateEnd = GetSelectedBusinessDate("#businessYearEnd", "#businessMonthEnd");
            var businessType = $('input:radio[name=BusinessType]:checked').val();



            var gridOpts = $('#dg').datagrid('getPager').data("pagination").options;
            $('#dg').datagrid('load', { ProcessType: 'QueryReport', BusinessDateStart: businessDateStart, BusinessDateEnd: businessDateEnd, BusinessType: businessType, page: gridOpts.pageNumber, rows: gridOpts.pageSize });
        }

热点排行