bootstrap Datatable搜索

$(document).ready(function(){
         loadentity();
       }
    );

      //加载实体列表
      function loadentity(){
          $('#example')
              .dataTable(
                  {
                    "sErrMode" : "throw",
                    "sDom" : '<lf>rt<lpi><"clear">',
                    "sServerMethod" : "POST",
                    "bDeferRender" : true,
                    "sScrollXInner" : "100%",
                    "bScrollCollapse" : false,
                    "bPaginate" : true,
                    "bLengthChange" : false,
                    "bFilter" : true, //打开搜索框
                    "bSort" : false,
                    "bInfo" : true,
                    "bAutoWidth" : false,
                    "bStateSave" : false,
                    "bProcessing" : true,
                    "iDisplayLength" : 10,
                    "aLengthMenu" : [ [ 50, 100, -1 ],
                        [ "50", "100", "所有" ] ],
                    "oLanguage" : {
                      "sLengthMenu" : "每页显示 _MENU_ 条记录",
                      "sZeroRecords" : "对不起,没有匹配的数据",
                      "sInfo" : "第 _START_ - _END_ 条 / 共 _TOTAL_ 条数据",
                      "sInfoEmpty" : "没有匹配的数据",
                      "sInfoFiltered" : "(数据表中共 _MAX_ 条记录)",
                      "sProcessing" : "正在加载中...",
                      "sSearch" : "按名称搜索:",
                      "oPaginate" : {
                        "sFirst" : "第一页",
                        "sPrevious" : " 上一页 ",
                        "sNext" : " 下一页 ",
                        "sLast" : " 最后一页 "
                      }
                    },
                    "aoColumns" : [
                        {
                          "mData" : 'name',
                          "sTitle" : "实体名称",
                          "bSortable" : false,
                          "mRender" : function(data, type, row) {
                            if(data==null){
                              return "";
                            }
                            return data;
                          }
                        },
                        {
                          "mData" : 'identity',
                          "sTitle" : "实体标识",
                          "bSortable" : false,
                          "mRender" : function(data, type, row) {
                            if(data==null){
                              return "";
                            }
                            return data;
                          }
                        },
                        {
                          "mData" : 'packageName',
                          "sTitle" : "实体包名",
                          "bSortable" : false,
                          "mRender" : function(data, type, row) {
                            if(data==null){
                              return "";
                            }
                            return data;
                          }
                        },
                        {
                          "mData" : 'description',
                          "sTitle" : "实体描述",
                          "bSortable" : false,
                          "mRender" : function(data,
                              type, row) {
                            return data;
                          }
                        },
                        {
                          "mData" : 'id',
                          "sTitle" : "操作",
                          "bSortable" : false,
                          "mRender" : function(data,
                              type, row) {
                            return '<button class=\"btn btn-primary\"> <a href=\"item.html?entityId=' + row.id +'\">属性管理</a> </button>'
                             + '&nbsp;&nbsp;&nbsp;'
                             + '<button class=\"btn btn-primary\" onClick=\"openUpdate(' + row.id +')\">修改实体</a> </button>'
                             + '&nbsp;&nbsp;&nbsp;'
                             + '<button class=\"btn btn-warning\" onClick=\"delete_entity(' + row.id +')\">删除实体</a> </button>';
                          }
                        } ],
                      "bServerSide": true,          //指定从服务器端获取数据
                      //"bFilter": false,           //不使用过滤功能
                      //"bLengthChange": false,         //用户不可改变每页显示数量
                      //"iDisplayLength": 8,          //每页显示8条数据
                      "sAjaxSource": "../entity/get_list.do",//获取数据的url
                      "fnServerData": retrieveData_devpro     //获取数据的处理函数
                  });
        }

      //自定义数据获取函数
      //table的一些参数都被封装在aoData中,想要看有什么参数debug一些就好了
      function retrieveData_devpro( sSource, aoData, fnCallback ) {
        var sEcho = aoData[0].value;
        var iDisplayStart = aoData[3].value;
        iDisplayStart = iDisplayStart/10 + 1;
        var iDisplayLength = aoData[4].value;
        var name = aoData[10].value; //这个是搜索框用户填写的数据
        $.post(sSource, {
          sEcho:sEcho,page:iDisplayStart,rows:iDisplayLength, "name":name 
        }, function(data) {
          var frontData = {
            "iTotalRecords": (data.totalCount == null) ? 0 : data.totalCount,
            "iTotalDisplayRecords": (data.totalCount == null) ? 0 : data.totalCount,
            "sEcho": sEcho,
             "aaData": (data.entityDTOList == null) ? 1 : data.entityDTOList
          };
          fnCallback(frontData);
        }, "json");
      }

    </script>

猜你喜欢

转载自blog.csdn.net/tszxlzc/article/details/69229934