• DataTable插件 后台分页 (服务器端分页)


      <script type="text/javascript">
            var persontable;

      var personQueryCondition = {

           //需要的查询条件放到这里来
                worksn: "",
                name: ""
            }

       $(document).ready(function () {

      persontable = $('#dataTables-custom').DataTable({
                    dom: '<t><"bp"i><"bp"p><"bp"l>',  //需要导出excel时打开
                    //dom: 'r<t><"dtpgclass"lp><"clear">',  //需要导出excel时打开
                    aLengthMenu: [10, 20, 100, 10000],
                    language: {
                        "sProcessing": "数据加载中...",
                        "sLengthMenu": "每页显示 _MENU_ 条记录",
                        "sZeroRecords": "没有匹配结果",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "sInfo": "当前显示第 _START_ 至 _END_ 项,共 _TOTAL_ 项",
                        "sInfoEmpty": "当前显示第 0 至 0 项,共 0 项"
                    },  //提示信息

                    serverSide: true,
                    ajax: function (data, callback, settings) {
                        var sortinfo = DatablesExtend.getSortInfo(data, settings);
                        if (sortinfo != null) {
                            $.extend(personQueryCondition, sortinfo);
                        }
                        //排序属性可通过data.order属性获得
                        $.ajax({
                            type: "POST",
                            url: LinkAddress.personQuery,
                            cache: false,  //禁用缓存
                            data: JSON.stringify(personQueryCondition),  //传入组装的参数
                            contentType: "application/json;",
                            dataType: "json",
                            beforeSend: function (xhr) {
                                xhr.setRequestHeader("Authorization", $.cookie('token'));
                            },
                            success: function (result) {
                                if (result.code == 0) {
                                    callback({
                                        draw: data.draw,
                                        data: result.orgs,
                                        recordsTotal: result.total,
                                        recordsFiltered: result.total
                                    });
                                }
                            }
                        });
                    },
                    columns: [
                        { "data": null, "orderable": false },
                        { "data": "worksn" },
                        { "data": "name" },
                        { "data": "sex" },
                        { "data": "irismodeStr" },
                        { "data": "orgs" },
                        { "data": null }
                    ],
                    order: [],
                    columnDefs: [{
                        "targets": 3,
                        "render": function (data, type, row, meta) {
                            if (data == 0) {
                                return '男';
                            }
                            else {
                                return '女';
                            }
                        }
                    }, {
                        "targets": 0,
                        "render": function (data, type, row, meta) {
                            return "<input type='checkbox' value='" + data.personid + "'>";
                        }
                    }, {
                        "targets": -1,
                        "render": function (data, type, row, meta) {
                            var d = data.personid;
                            var da = JSON.stringify({ personid: data.personid, name: data.name, worksn: data.worksn });
                            return "<a href='#' data-page='showpersoninfo' data-param=" + d + " onclick='pageRedirect(this)'>  查看  </a><a href='#' data-page='editperson' data-param=" + d + " onclick='pageRedirect(this)'>  编辑  </a><a href='#' data-page='bindingdev' data-param=" + da + " onclick='pageRedirect(this)'>  关联设备  </a><a href='#' data-param=" + d + " onclick='deletea(this)'>  删除  </a>";
                        }
                    }],
                    deferRender: true,
                    processing: true,
                    scrollY: '50vh',
                    scrollCollapse: false,
                    scroller: {
                        loadingIndicator: true
                    },
                    searching: false,
                    stateSave: false,
                    paging: true,
                    pageLength: 10,
                    //select: true,
                    buttons: [{
                        extend: 'excelHtml5',
                        title: 'Data export'
                    }],
                });

           });

    需要查询的时候 只需要执行 : 把查询条件更新一下,然后执行  persontable.ajax.reload(); 这句话就好了

  • 相关阅读:
    test
    Android初学-AsyncTask下载网络图片
    SFTP Using Chilkat Active component
    test wilddog
    c# multi-ply download ui
    VB6 Common Dialog
    Advanced Find and Replace(文件内容搜索替换工具)v7.8.1简体中文破解版
    【Unity Shaders】Shader中的光照
    GDAL不支持创建PCIDSK的面状矢量格式
    CentOs查看文件的几种方式
  • 原文地址:https://www.cnblogs.com/tony-brook/p/9679924.html
Copyright © 2020-2023  润新知