濮阳杆衣贸易有限公司

主頁 > 知識庫 > php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼

php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼

熱門標(biāo)簽:天潤融通外呼系統(tǒng)好嗎 電銷機器人沒有效果怎么樣 高德地圖標(biāo)注店鋪收費嗎 欣思維地圖標(biāo)注 杭州語音電銷機器人 江西電銷機器人收費 高德地圖標(biāo)注位置怎么標(biāo)注 泊頭在哪里辦理400電話 江門回?fù)芡夂粝到y(tǒng)

一、HTML

table class="layui-hide layui-table" id="spu-data">/table>

二、JS

說明:需要引入layui中的table和laytpl模板引擎,laytpl可以自定義事件及自定義數(shù)據(jù)字段等

!-- 拼接圖片 -->
script type="text/html" id="pimg">
 img class="img" onmouseover="divIn(event)" onmouseout="divOut(event)" onmousemove="divIn(event)" src="__PUBLIC__/{{d.pimgurl}}t_{{d.pimgname}}" alt="">
/script>

!-- 查看詳情按鈕 -->
script type="text/html" id="spu_detail">
 button class="layui-btn layui-btn-xs layui-btn-primary spu_detail" artnum="{{d.artnum}}" value="{{d.basic_id}}" onclick="spuDetail(event)">查看詳情/button>
/script>

script type="text/html" id="hotcake_color">
 {{# if (d.hotcake === '超級爆款') { }} 
  span style="display: block;background-color: #CCFFCC;">{{ d.hotcake }}/span>
 {{# } else if(d.hotcake === '大爆款') { }} 
  span style="display: block;background-color: #99CCCC;">{{ d.hotcake }}/span> 
 {{# } else if(d.hotcake === '小爆款') { }} 
  span style="display: block;background-color: #FFCCCC;">{{ d.hotcake }}/span> 
 {{# } else if(d.hotcake === '熱銷款') { }} 
  span style="display: block;background-color: #FFFFCC;">{{ d.hotcake }}/span> 
 {{# } else { }} 
  span style="display: block;background-color: #CCFFFF;">{{ d.hotcake }}/span> 
 {{# } }} 
/script>
script type="text/javascript">

layui.use(['form','laydate','layer','table','laytpl'],function(){
 var laydate = layui.laydate;
 var layer = layui.layer;
 var table = layui.table;
 var laytpl = layui.laytpl;

  //---SPU數(shù)據(jù)---------------------------------------------
 var spu_table = table.render({
  elem: '#spu-data',   //html中table窗口的id
  height: 800,
  url: '__URL__/spu_data', //后臺接口
  toolbar: true,
  loading: true,
  text: {
   none: '空空如也'
  },
  title: 'spu數(shù)據(jù)',
  size: 'sm',
  page: {
   layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
   limit: 20,
   limits: [20,30,50,100,200,5000]
  },
  cols: [[
    {field:'n', title: 'i', width: 55},
    {field:'', title: '圖', width: 31, templet: '#pimg'},     // templet 引用laytpl中的自定義模板
    {field:'', title: '查看詳情', width: 120, templet: '#spu_detail'},  // 引用laytpl中的自定義模板
    {field:'artnum', title: '貨號', sort: true},
    {field:'gcolor', title: '顏色組', sort: true},
    {field:'cate', title: '品類', sort: true},
    {field:'price', title: '業(yè)績', sort: true},
    {field:'sales', title: '銷量', sort: true},
    {field:'hotcake', title: '熱銷程度', templet: '#hotcake_color', sort: true},
    {field:'sumcost', title: '商品成本', sort: true}
  ]]
 });

// 搜索重載數(shù)據(jù)
 $('#spudata_search').click(function(){
  // 獲取日期的值
  var date = $('#spusearch_date').val();
  if (!date) {
   layer.msg('請選擇日期區(qū)間搜索', {
    time: 2000
   });
   return false;
  }

  var perfor_val = $('#perfor_val').val();;
  var hot_type = $('#hot_type').val();
  var artnum = $('#artnum').val();
  var cate_id = $('#cate_id').val();

  // 只選其一條件
  if (perfor_val  hot_type) {
   layer.msg('業(yè)績區(qū)間和爆款類型只選其一', {
    time: 2000
   });
   return false;
  }

  // 數(shù)據(jù)重載
  spu_table.reload({
   // 發(fā)送條件
   where: {
    artnum: artnum,
    perfor_val: perfor_val,
    hot_type: hot_type,
    cate_id: cate_id,
    date: date,
    act: 'reload'
   },
   page: {
    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
    curr: 1
   }
  });

 })

}) 
/script>

三、PHP

#這里是PHP類中主要的配合步驟

# 接收layui發(fā)送的limit
if (trim($_GET['limit'])) {
 $limit = trim($_GET['limit']);
}else{
 $limit = 15;
}

# 按某字段排序,$rows為數(shù)據(jù)數(shù)組
$sort_num = array_column($rows,'num');
array_multisort($sort_num,SORT_DESC,$rows, SORT_DESC);

# 調(diào)用自定義分頁函數(shù)
$datas = array();
$datas = showpage($rows,$limit);

$items = array();

# 返回layui數(shù)據(jù)格式
$items['data'] = $datas['rows'];
$items['code'] = 0;
$items['msg'] = 'ok';
$items['count'] = $datas['tot'];

exit(json_encode($items));
# showpage函數(shù)

function showpage($rows,$count){ 
 $tot = count($rows); // 總數(shù)據(jù)條數(shù)

 if ($_GET['page']) { //獲取當(dāng)前頁碼
  $page = $_GET['page'];
 }else{
  $page = 1;
 }

 // $count = $count; # 每頁顯示條數(shù)

 $countpage = ceil($tot/$count); # 計算總共頁數(shù)

 $start = ($page-1)*$count; # 計算每頁開始位置

 $datas = array_slice($rows, $start, $count); # 計算當(dāng)前頁數(shù)據(jù)

 # 獲取上一頁和下一頁
 if ($page > 1) {
  $uppage = $page-1;
 }else{
  $uppage = 1;
 }

 if ($page  $countpage) {
  $nextpage = $page+1;
 }else{
  $nextpage = $countpage;
 }

 $pages['countpage'] = $countpage;
 $pages['page'] = $page;
 $pages['uppage'] = $uppage;
 $pages['nextpage'] = $nextpage;
 $pages['tot'] = $tot;

 //循環(huán)加入序號 , 避免使用$i引起的序號跳位
 $n = 1;
 foreach ($datas as $data) {
  $data['n'] = $n;
  $n++;
 }
 
 $pages['rows'] = $datas;

 return $pages;
}

以上這篇php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • thinkphp5+layui實現(xiàn)的分頁樣式示例
  • layui+jquery支持IE8的表格分頁方法
  • layui 數(shù)據(jù)表格+分頁+搜索+checkbox+緩存選中項數(shù)據(jù)的方法
  • layui table 獲取分頁 limit的方法
  • 淺談layui分頁控件field參數(shù)接收對象的問題
  • 淺談layui框架自帶分頁和表格重載的接口解析問題
  • Layui之table中的radio在切換分頁時無法記住選中狀態(tài)的解決方法
  • layui表格分頁 記錄勾選的實例
  • Layui實現(xiàn)數(shù)據(jù)表格默認(rèn)全部顯示(不要分頁)

標(biāo)簽:雙鴨山 內(nèi)江 駐馬店 石嘴山 深圳 江門 大同

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼》,本文關(guān)鍵詞  php+layui,數(shù)據(jù),表格,實現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于php+layui數(shù)據(jù)表格實現(xiàn)數(shù)據(jù)分頁渲染代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    礼泉县| 昌江| 靖远县| 恭城| 澎湖县| 荣成市| 南开区| 六盘水市| 岑巩县| 建始县| 故城县| 聂拉木县| 精河县| 清涧县| 工布江达县| 桑日县| 城固县| 平顺县| 林甸县| 广昌县| 乡城县| 祥云县| 竹北市| 柞水县| 曲靖市| 姚安县| 青铜峡市| 辛集市| 巴林左旗| 安西县| 汶川县| 洞头县| 晋城| 巫溪县| 高密市| 台东县| 泸定县| 滨州市| 永昌县| 瑞安市| 清镇市|