datatable 伺服器端分頁

2022-07-30 22:33:14 字數 4413 閱讀 1562

html**

<

table

cellpading

="0"

cellspacing

="0"

border

="0"

class

="dtable acelisttable"

>

<

thead

>

<

tr>

<

th>使用者名稱

th>

<

th>跟隨

th>

<

th>新外匯指數

th>

<

th>月均交易(手)

th>

<

th>賬戶餘額($)

th>

<

th>近乙個月收益

th>

<

th>當前持倉(單)

th>

<

th>浮動收益($)

th>

<

th>狀態

th>

<

th>操作

th>

tr>

thead

>

<

tfoot

>

<

tr>

<

th>使用者名稱

th>

<

th>跟隨

th>

<

th>新外匯指數

th>

<

th>月均交易(手)

th>

<

th>賬戶餘額($)

th>

<

th>近乙個月收益

th>

<

th>當前持倉(單)

th>

<

th>浮動收益($)

th>

<

th>狀態

th>

<

th>操作

th>

tr>

tfoot

>

table

>

js**

var otable = $('.acelisttable').datatable(

}global/img/ajaxloader/loader01.gif' />

", //

這裡是給伺服器發請求後到等待時間顯示的 載入gif

"opaginate":

},"bprocessing": true, //

開啟讀取伺服器資料時顯示正在載入中……特別是大資料量的時候,開啟此功能比較好

"bserverside": true, //

"sajaxsource": "}ace_management/ace_list", //

給伺服器發請求的url

"aocolumns": [ //

這個屬性下的設定會應用到所有列,按順序沒有是空

, //

mdata 表示發請求時候本列的列明,返回的資料中相同下標名字的資料會填充到這一列,,

,,,,

,, //

sdefaultcontent 如果這一列不需要填充資料用這個屬性,值可以不寫,起佔位作用

,//sclass 表示給本列加class

], "aocolumndefs": [//

和aocolums類似,但他可以給指定列附近愛屬性

, //

這句話意思是第1,3,6,7,8,9列(從0開始算) 不能排序

, //

bsearchable 這個屬性表示是否可以全域性搜尋,其實在伺服器端分頁中是沒用的

],"aasorting": [[2, "desc"]], //預設排序

"fnrowcallback": function(nrow, adata, idisplayindex)

else

if (adata.status == 4)

else

if (adata.active == 0)

else

$('td:eq(9)', nrow).html("詳情");

if (adata.status != 1 && adata.status != 4 && adata.active == 0)

else

if (adata.status != 1 && adata.status != 4 && adata.active == 1)

return

nrow;

},"fninitcomplete": function(osettings, json)

});

伺服器端**

先說一下我們需要的目標格式是這樣

是乙個json串

接著上php**

$secho = xutil::xget('secho'); //

datatables 用來生成的資訊

$start = xutil::xget('idisplaystart'); //

顯示的起始索引

$length = xutil::xget('idisplaylength');//

顯示的行數

$sort_th = xutil::xget('isortcol_0');//

被排序的列

$sort_type = xutil::xget('ssortdir_0');//

排序的方向 "desc" 或者 "asc".

$search = xutil::xget('ssearch');//

全域性搜尋字段

//下面的**就是根據上面的資訊取資料並且組織資訊

$agent_id = $this->vdata['agent_user']->id;

if ($sort_th == 2)

elseif ($sort_th == 4)

elseif ($sort_th == 5)

else

$total = agentutil::get_total_ace_acount($agent_id

);$price_table = $this->get_price_table();

$sql = "select aul.user_id ,

cu.nickname,

et.rank,

ea.equity,

et.month_ror,

aul.active,

cmt.`status`,

cmt.fail_type

from agent_user_list aul

left join common_userprofile cu on cu.user_id = aul.user_id

left join ea_traderlistindex et on et.user_id = aul.user_id

left join ea_account ea on ea.id = et.account_id

left join common_mt4_trusteeship cmt on cmt.user_id = aul.user_id

where et.visible = 1 and aul.agent_id = and aul.type=1 and cu.nickname like '%%'

order by

limit ,";

$res = doo::db()->fetchall($sql

);$display_total = count($res

);$aadata = array

();foreach ($res

as$k => $v

) $output['secho'] = $secho

;if ($search)

else

$output['itotalrecords'] = $total; //

總共有幾條資料

$output['aadata'] = $aadata

;echo json_encode($output); //

最後把資料以json格式返回

上面displaytotal的處理方式有問題,當全域性搜尋存在時, displaytotal等於按條件搜尋的全部數量,注意自己該下

有個需求要求開啟某個頁面,會自動列出所有資料,然後上面有表單個提交,要求提交表單後**資料重新整理。

實現辦法就是表單用js驗證成功後組織乙個加上引數的url,最後

var osettings =otable.fnsettings();

osettings.sajaxsource =new_filter_url;

otable.fndraw();

datatable 筆記 伺服器端查詢

var vtable vip data datatable ajax data,vtable vtable 自身準備的請求資料 fndrawcallback function data columns 第一列 顯示為 請求道的資料 vid id columndefs 初始化後 再次請求 vtable...

BootstrapTable伺服器端分頁

兩個個關鍵點 1 引數 sidepagination為server,queryparams傳遞引數 sidepagination server pagination true,分頁 pagesize 10,pagenumber 1,queryparamstype queryparams functi...

socket伺服器端

伺服器 include winsock2.h include string.h include stdio.h include time.h include stdarg.h include stdlib.h pragma comment lib,ws2 32 void errexit const ...