tp5使用layui表格_layui TP5 方法渲染 完整数据表格例子(JSON) 传递排序、搜索等参数...

本文介绍了如何在ThinkPHP5(简称tp5)框架下结合layui前端组件库,实现表格的数据渲染、排序和搜索功能。通过控制器处理请求参数,从数据库获取并过滤数据,最后返回JSON格式的数据给layui表格展示。
摘要由CSDN通过智能技术生成

官方例子:https://www.layui.com/doc/modules/table.html#methodRender

一、模板

优惠券

请选择搜索类型

标题

搜索

二、控制器  数据 ,url: '{:url('index')}?action=usertable'

$action=input('action');

$sotitle=input('sotitle');

$sotype=input('sotype');

$limit=input('limit');

$limit=$limit?$limit:10;

$this->assign('sotype',$sotype);

$page=input('page');//页数

$starttime=input('starttime');//创建开始时间

$enttime=input('enttime');//创建结束时间

$field=input('field');//字段

$order=input('order');//排序方式

//排序

if($field){

$od=$field." ".$order;

}else{

$od="id desc";

}

$where['deleted'] = 0;//状态 0正常 1回收站

$rsu=Db::name('user')->where($where)->order($od)->limit($limit)->page($page)->select();

$rsu1=Db::name('user')->where($where)->select();

$count = count($rsu1);//取得记录集总条数

json(0,'数据返回成功',$count,$rsu);

return $data;

json函数

/**

* 格式函数 专门把数据录格式成为layui 数据表格的格式

*/

function json($code,$msg="",$count,$data=array()){

$result=array(

'code'=>$code,

'msg'=>$msg,

'count'=>$count,

'data'=>$data

);

//输出json

echo json_encode($result);

exit;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值