DataTables 用法积累

 function loadData() {
            var areaTable = $('#area').dataTable({
                "autoWidth": false,
                "scrollY": "380px",//树形滚动条
                "ordering": false, // 禁止排序
                "scrollCollapse": true,
                "destroy": true, //Cannot reinitialise DataTable,解决重新加载表格内容问题,可以重复调用loadData()
                "ajax": {
                    "url": "/baidu/getdata",
                    "data": function (data) {
                        //添加额外的参数传给服务器
                        data.inputDept = $("#inputDept option:selected").val();
                        data.date1 = $("#date1").val();
                        data.date2 = $("#date2").val();
                        data.addArea = $("#addArea").val();
                        data.personName = $("#txt_personName").val();
                        data.customerName = $("#txt_userName").val();
                        data.mobile = $("#txt_mobile").val();

                        return JSON.stringify(data);//指定json格式,如果不指定默认为 name=aa$userid=124&sex=1 这样的格式
                    },
                    "dataSrc": function(json){ //服务端返回错误数据在绑定之前处理
                        if (json.Status == 0) {
                            layer.alert(json.Message, {title:'错误信息',icon:5});
                            return false;
                        }
                        return json.data;
                    }
                }, 
                "fnDrawCallback": function (oSettings) {
                  
                    var json = jQuery.parseJSON(oSettings.jqXHR.responseText);//获取后台方式 直接可以拿到json 之后进行处理 只能拿到成功以后的数据
                    
                },
              
                "columnDefs": [
                    {
                        "targets": 0,
                        "width": "50px",
                        render: function (data, type, full, meta) {
                            return '' + full.TableID + '';
                        }

                    },
                    {
                        "targets": 11,
                        "width": "50px",
                        render: function (data, type, full, meta) {
                            var statusHtml = "";
                            statusHtml = "<span οnclick='openDiv(500,500,\"/c.html?id=" + full.TableID +"\",\"详细信息\",\"\")' >详情 <i class='glyphicon glyphicon-list-alt text-success' ></i></span>";
                           
                            return statusHtml;
                        }
                    },
                    {
                    }
                ]
            });

            SearchGo = function () {
                areaTable.api().ajax.reload();
            }
            CurrentPageRefresh = function () {
                areaTable.api().ajax.reload(null, false);  //刷新表格数据,分页信息不会重置
            }

         
        }

标题排序设置:
   <table id="area" class="table table-striped table-bordered" data-page-length="10" data-order="[[0,&quot;desc&quot;]]">

排序后端接收数据:

            //获取客户端需要那一列排序
            string orderColumn = "0";
            //获取排序方式 默认为asc
            string orderDir = "asc";
            //定义列名,顺序要和表头顺序一致,不需要排序的可以空出来,但是必须要有,占一个索引位置
            string[] cols = { "TableID", "CustomerName", "mobile", "YiXiang", "AddArea", "personid","","", "CreateDate" };


       var jsonOrderItems = JsonConvert.DeserializeObject<List<OrderModel>>(obj["order"].ToString().Trim(new char[] { '"' }));
                orderColumn = jsonOrderItems[0].column;
                orderColumn = cols[int.Parse(orderColumn)];
                orderDir = jsonOrderItems[0].dir;

        List<int> OrderFilter = new List<int>();
        
            if (orderDir == "asc")
            {
                OtherCustomerInputInfo.Fields fields = (OtherCustomerInputInfo.Fields)Enum.Parse(typeof(OtherCustomerInputInfo.Fields), orderColumn, true);
                BLLLogicHelper.OtherCustomerInputLogic.EnumToOrderByEnum(OrderFilter, fields, SortingAction.Asc);
            }
            else
            {
                OtherCustomerInputInfo.Fields fields = (OtherCustomerInputInfo.Fields)Enum.Parse(typeof(OtherCustomerInputInfo.Fields), orderColumn, true);
                BLLLogicHelper.OtherCustomerInputLogic.EnumToOrderByEnum(OrderFilter, fields, SortingAction.Desc);
            } 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值