最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Bootstrap table學(xué)習(xí)筆記(2) 前后端分頁(yè)模糊查詢

 更新時(shí)間:2017年05月18日 09:07:17   作者:鄧曉暉  
這篇文章主要為大家分享了Bootstrap table學(xué)習(xí)筆記,前后端分頁(yè)模糊查詢,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在使用過(guò)程中,一邊看文檔一邊做,遇到了一些困難的地方,在此記錄一下,順便做個(gè)總結(jié):

1、前端分頁(yè)
2、后端分頁(yè)
3、模糊查詢

前端分頁(yè)相當(dāng)簡(jiǎn)單,在我添加了2w條測(cè)試數(shù)據(jù)的時(shí)候打開(kāi)的很流暢,沒(méi)有卡頓。

$(function(){
  a();

});
  function a () {
    $('#yourtable').bootstrapTable({
      url: "/user/getUserList/",
      method:"post",
      dataType: "json",
      striped:true,//隔行變色
      cache:false,  //是否使用緩存
      showColumns:false,// 列
      pagination: true, //分頁(yè)
      sortable: false, //是否啟用排序
      singleSelect: false,
      search:false, //顯示搜索框
      buttonsAlign: "right", //按鈕對(duì)齊方式
      showRefresh:false,//是否顯示刷新按鈕
      sidePagination: "client", //客戶端處理分頁(yè) 服務(wù)端:server
      pageNumber:"1",  //啟用插件時(shí)默認(rèn)頁(yè)數(shù)
      pageSize:"15",  //啟用插件是默認(rèn)每頁(yè)的數(shù)據(jù)條數(shù)
      pageList:[10, 25, 50, 100],  //自定義每頁(yè)的數(shù)量
      undefinedText:'--', 
      uniqueId: "id", //每一行的唯一標(biāo)識(shí),一般為主鍵列
      queryParamsType:'',
      columns: [
        {
          title: 'ID',
          field: 'id',
          align: 'center',
          valign: 'middle',
        },
        {
          title: '用戶姓名',
          field: 'name',
          align: 'center',
          valign: 'middle',
        },
        {
          title: '性別',
          field: 'sex',
          align: 'center',
        },
        {
          title: '用戶賬號(hào)',
          field: 'username',
          align: 'center',
        },
        {
          title: '手機(jī)號(hào)',
          field: 'phone',
          align: 'center',
        },
        {
          title: '郵箱',
          field: 'email',
          align: 'center',
        },
        {
          title: '權(quán)限',
          field: 'rolename',
          align: 'center',
        },
        {
          title: '操作',
          field: 'id',
          align: 'center',
          formatter:function(value,row,index){
              //value 能夠獲得當(dāng)前列的值
              //====================================

            var e = '<button href="#" class="btn btn-default" mce_href="#" onclick="edit(\''+ row.id + '\')">編輯</button> ';
            var d = '<button href="#" class="btn btn-default" mce_href="#" onclick="del(\''+ row.id +'\')">刪除</button> ';
            return e+d;
          }
        }
      ]
    });

  }

考慮到以后的數(shù)據(jù)會(huì)越來(lái)越多,前端分頁(yè)在數(shù)據(jù)量大的情況下,明顯不能滿足要求,因此必須要做后端的分頁(yè)

首先:

sidePagination: "server",//服務(wù)器分頁(yè)

queryParams: queryParams,//傳遞參數(shù)(*)

//得到查詢的參數(shù)
    function queryParams (params) {
      var temp = {  //這里的鍵的名字和控制器的變量名必須一直,這邊改動(dòng),控制器也需要改成一樣的
        pageSize: params.pageSize,  //頁(yè)面大小
        pageNumber: params.pageNumber, //頁(yè)碼
        username: $("#search_username").val(),
        name:$("#search_name").val(),
        sex:$("#search_sex").val(),
        phone:$("#search_mobile").val(),
        email:$("#search_email").val(),
      };
      return temp;
    };


這里傳入了每頁(yè)顯示的條數(shù)、以及當(dāng)前的頁(yè)數(shù)。如果需要查詢,則需要傳入需要查詢的條件。

具體的js如下:

$(function(){
  a();

});
  function a () {
    $('#userListTable').bootstrapTable({
      url: "/user/getUserList/",
      method:"post",
      dataType: "json",
      contentType: "application/x-www-form-urlencoded",
      striped:true,//隔行變色
      cache:false,  //是否使用緩存
      showColumns:false,// 列
      toobar:'#toolbar',
      pagination: true, //分頁(yè)
      sortable: false,           //是否啟用排序
      singleSelect: false,
      search:false, //顯示搜索框
      buttonsAlign: "right", //按鈕對(duì)齊方式
      showRefresh:false,//是否顯示刷新按鈕
      sidePagination: "server", //服務(wù)端處理分頁(yè)
      pageNumber:"1",
      pageSize:"15",
      pageList:[10, 25, 50, 100],
      undefinedText:'--',
      uniqueId: "id", //每一行的唯一標(biāo)識(shí),一般為主鍵列
      queryParamsType:'',
      queryParams: queryParams,//傳遞參數(shù)(*)
      columns: [
        {
          title: 'ID',
          field: 'id',
          align: 'center',
          valign: 'middle',
        },
        {
          title: '用戶姓名',
          field: 'name',
          align: 'center',
          valign: 'middle',
        },
        {
          title: '性別',
          field: 'sex',
          align: 'center',
        },
        {
          title: '用戶賬號(hào)',
          field: 'username',
          align: 'center',
        },
        {
          title: '手機(jī)號(hào)',
          field: 'phone',
          align: 'center',
        },
        {
          title: '郵箱',
          field: 'email',
          align: 'center',
        },
        {
          title: '權(quán)限',
          field: 'rolename',
          align: 'center',
        },
        {
          title: '操作',
          field: 'id',
          align: 'center',
          formatter:function(value,row,index){
            var e = '<button href="#" class="btn btn-default" mce_href="#" onclick="edit(\''+ row.id + '\')">編輯</button> ';
            var d = '<button href="#" class="btn btn-default" mce_href="#" onclick="del(\''+ row.id +'\')">刪除</button> ';
            return e+d;
          }
        }
      ]
    });

    //得到查詢的參數(shù)
    function queryParams (params) {
      var temp = {  //這里的鍵的名字和控制器的變量名必須一直,這邊改動(dòng),控制器也需要改成一樣的
        pageSize: params.pageSize,  //頁(yè)面大小
        pageNumber: params.pageNumber, //頁(yè)碼
        username: $("#search_username").val(),
        name:$("#search_name").val(),
        sex:$("#search_sex").val(),
        phone:$("#search_mobile").val(),
        email:$("#search_email").val(),
      };
      return temp;
    };
  }

//搜索
function serachUser() {
  $("#userListTable").bootstrapTable('refresh');
}

*值得注意的是:

contentType:  "application/x-www-form-urlencoded",  //因?yàn)閎ootstap table使用的是ajax方式獲取數(shù)據(jù),這時(shí)會(huì)將請(qǐng)求的content type默認(rèn)設(shè)置為 text/plain,這樣在服務(wù)端直接通過(guò) @RequestParam參數(shù)映射是獲取不到的。
以及:

HTML:

<div id="page-content" class="animated fadeInRight">
  <div class="col-sm-4 col-md-3 col-lg-3" style="width: 100%;">
    <form  id="search_User">
      <div class="panel-body search_box">
        <div class="search_div">
          <label for="search_name">用戶姓名:</label>
          <input type="text" class="form-control" id="search_name" name="UserV2.name" >
        </div>
        <div class="search_div">
          <label for="search_mobile">手機(jī)號(hào):</label>
          <input type="text" class="form-control" id="search_mobile" name="UserV2.phone" >
        </div>
        <div class="search_div">
          <label for="search_sex">性別:</label>
          <select class="form-control" id="search_sex" name="UserV2.sex"><option value="">---請(qǐng)選擇---</option><option value="男">男</option><option value="女">女</option></select>
        </div>
      </div>
      <div class="panel-body search_box">
        <div class="search_div">
          <label for="search_name">用戶賬號(hào):</label>
          <input type="text" class="form-control" id="search_username" name="UserV2.username" >
        </div>
        <div class="search_div">
          <label for="search_name">用戶Email:</label>
          <input type="text" class="form-control" id="search_email" name="UserV2.email" >
        </div>
        <div class="search_div" style="text-align: center;">
          <input type="button" class="btn btn-primary btn_search" value="搜索" onclick="serachUser()"/>
        </div>
      </div>
    </form>
  </div>
  <table id="userListTable" ></table>
</div>

不論是初始化表格還是搜索的時(shí)候傳入后臺(tái)的數(shù)據(jù)如下:

 pageSize=15   pageNumber=1  username=   name=   sex=   phone=   email=  

返回?cái)?shù)據(jù):

我們要返回兩個(gè)值: rows     total

rows:我們查詢到的數(shù)據(jù)  

total:數(shù)據(jù)總數(shù)(此總數(shù)指的是所有數(shù)據(jù)的總數(shù),并不是單頁(yè)的數(shù)量,比如說(shuō)我有user表中有100條數(shù)據(jù),我的limit 0,15,所以我的rows中有15條數(shù)據(jù),但是total=100)

{
  "total": 2,
  "rows": [
    {
      "email": "39385908@qq.com",
      "id": 1,
      "name": "鄧某某",
      "password": "",
      "phone": "12345678911",
      "rolename": "平臺(tái)管理員",
      "sex": "男",
      "username": "admin"
    },
    {
      "email": "2222@222.com",
      "id": 8,
      "name": "王小二1",
      "password": "",
      "phone": "13245678910",
      "rolename": "",
      "sex": "男",
      "username": "admin2"
    }
  ]
}

有了total總數(shù),加上之前的pageSize以及rows,bootStraptable會(huì)為我們自動(dòng)生成和分頁(yè)有關(guān)的元素:

效果圖:

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 利用JQuery和JS實(shí)現(xiàn)奇偶行背景顏色自定義效果

    利用JQuery和JS實(shí)現(xiàn)奇偶行背景顏色自定義效果

    本文將詳細(xì)介紹利用JQuery和JS實(shí)現(xiàn)奇偶行背景顏色自定義效果,需要的朋友可以參考下
    2012-11-11
  • JavaScript ES2019中的8個(gè)新特性詳解

    JavaScript ES2019中的8個(gè)新特性詳解

    這篇文章主要介紹了JavaScript ES2019中的8個(gè)新特性詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-02-02
  • 解析使用JS 清空File控件的路徑值

    解析使用JS 清空File控件的路徑值

    本篇文章是對(duì)使用JS清空File控件的路徑值的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-07-07
  • 小發(fā)現(xiàn)之淺談location.search與location.hash的問(wèn)題

    小發(fā)現(xiàn)之淺談location.search與location.hash的問(wèn)題

    下面小編就為大家?guī)?lái)一篇小發(fā)現(xiàn)之淺談location.search與location.hash的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • JS彈出居中的DIV的代碼

    JS彈出居中的DIV的代碼

    一直都在想怎么樣使彈出的DIV能在任何時(shí)候都是居中顯示的,剛開(kāi)始的時(shí)候是用CSS樣式直接定義好層的位置,但是當(dāng)頁(yè)面很長(zhǎng)的時(shí)候,或是瀏覽器窗口大小不是固定的時(shí)候就不能正確的顯示,所以只好用JS來(lái)控制DIV的顯示位置。
    2008-06-06
  • javascript隨機(jī)生成用戶名的實(shí)現(xiàn)方式

    javascript隨機(jī)生成用戶名的實(shí)現(xiàn)方式

    這篇文章主要介紹了javascript隨機(jī)生成用戶名的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • JS ES6異步解決方案

    JS ES6異步解決方案

    這篇文章主要介紹了JS ES6異步解決方案,對(duì)異步感興趣的同學(xué),可以參考下
    2021-04-04
  • 基于javascript實(shí)現(xiàn)漂亮的頁(yè)面過(guò)渡動(dòng)畫(huà)效果附源碼下載

    基于javascript實(shí)現(xiàn)漂亮的頁(yè)面過(guò)渡動(dòng)畫(huà)效果附源碼下載

    本文通過(guò)javascript實(shí)現(xiàn)漂亮的頁(yè)面過(guò)濾動(dòng)畫(huà)效果,用戶通過(guò)點(diǎn)擊頁(yè)面左側(cè)的菜單,對(duì)應(yīng)的頁(yè)面加載時(shí)伴隨著滑動(dòng)過(guò)濾動(dòng)畫(huà),并帶有進(jìn)度條效果。用戶體驗(yàn)度非常好,感興趣的朋友一起看看吧
    2015-10-10
  • 詳解用async/await來(lái)處理異步

    詳解用async/await來(lái)處理異步

    這篇文章主要介紹了詳解用async/await來(lái)處理異步,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 網(wǎng)頁(yè)中的圖片的處理方法與代碼

    網(wǎng)頁(yè)中的圖片的處理方法與代碼

    昨天的一篇 圖片的alt屬性 文章評(píng)論中的啟發(fā),特將網(wǎng)頁(yè)中的圖片的一些處理方法 小小的總結(jié)一下
    2009-11-11

最新評(píng)論

彰化县| 大城县| 岳西县| 大英县| 汕头市| 新龙县| 斗六市| 富川| 北碚区| 秦安县| 常宁市| 昌邑市| 永吉县| 平果县| 中阳县| 县级市| 淅川县| 葵青区| 临汾市| 肃北| 漳平市| 阿城市| 武功县| 偃师市| 林芝县| 剑河县| 红河县| 崇文区| 三河市| 龙岩市| 宁德市| 青岛市| 奎屯市| 荔波县| 清徐县| 齐齐哈尔市| 广平县| 莱州市| 双柏县| 瑞金市| 治多县|