jquery dataTables例子
2017-01-19 15:47 youxin 阅读(1085) 评论(0) 编辑 收藏 举报https://datatables.net/examples/styling/bootstrap.html
http://datatables.club/example/#styling
http://blog.csdn.net/hefangju/article/details/50333609'
http://www.cnblogs.com/Leo_wl/p/4289289.html
http://www.guoxk.com/node/jquery-datatables
http://stackoverflow.com/questions/11011796/trying-to-custom-style-datatables-table
http://stackoverflow.com/questions/5509303/customized-table-style-when-using-jquery-datatables
ajax:
https://datatables.net/manual/server-side
https://datatables.net/examples/data_sources/server_side.html
return:
draw |
integer |
The draw counter that this object is a response to - from the draw parameter sent as part of the data request. Note that it is strongly recommended for security reasons that you cast this parameter to an integer, rather than simply echoing back to the client what it sent in the draw parameter, in order to prevent Cross Site Scripting (XSS) attacks. |
recordsTotal |
integer |
Total records, before filtering (i.e. the total number of records in the database) |
recordsFiltered |
integer |
Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data). |
data |
array |
The data to be displayed in the table. This is an array of data source objects, one for each row, which will be used by DataTables. Note that this parameter's name can be changed using the ajax option's dataSrc property. |
error |
string |
Optional: If an error occurs during the running of the server-side processing script, you can inform the user of this error by passing back the error message to be displayed using this parameter. Do not include if there is no error. |
laravel eloquent limit offset
$users = DB::table('users')->skip(10)->take(5)->get();
https://laravel-china.org/docs/5.1/queries#ordering-grouping-limit-and-offset
ajax例子:
https://coderexample.com/jquery-datatable-with-custom-json-format-in-php-mysql
columndefs:
https://datatables.net/reference/option/columnDefs
targets:
- 0 or a positive integer - column index counting from the left
- A negative integer - column index counting from the right
- A string - class name will be matched on the TH for the column
- The string
_all
- all columns (i.e. assign a default)
targets也可以是一个数组。
targets: [ -1, -2 ]
would target the last and second last columns in the table.
var
table = $(
'#myTable'
).DataTable( {
columnDefs: [
{ targets: [0, 1], visible:
true
},
{ targets:
'_all'
, visible:
false
}
]
} );
columns
这个指定了传过来的数据的字段,visible字段默认是true,如果设置false的话,显示的时候是隐藏的,当然也可以通过空间取消其隐藏。 发现columns不仅传给服务器,客户端也会用到。
columns:[
{data:"name_id"},
{data:"id",},
我把name_id和id调换,值也会调换。
设置某列宽度
columns:[
{data:"id",width:'50%',},
还可以在columns设置orderorderable: false ,
columns会传给服务器。
post给服务器的类似:
..
$(
'#example'
).dataTable( {
"columnDefs"
: [
{ className:
"my_class"
,
"targets"
: [ 0 ] }
]
} );
$('#datatable_demo').DataTable( { "processing": true, "serverSide": true, "ajax": { "url": "server-json-data.php", "type": "POST", "dataSrc": "records" }, "columns": [ { "data": "invoice_no" }, 、、这里data返回指定的列名 ,如果默认可以写为null. { "data": "product_name" }, { "data": "delivery_status" }, { "data": "pin_code" }, ], "columnDefs": [ { "targets": 2, "render": function ( data, type, row,meta ) { return data == 1 ? 'Delivered': 'Not delivered'; } }, { "targets": 3, "render": function ( data, type, row ,meta) { return row["city"] +', ' + row["country"] +', '+data; }, }, ] });
$('#example').dataTable( {
"columns": [
{ "searchable": false },
null,
null,
null,
null
]
} );
禁止sort:
columnDefs:[ // {targets:0,visible:false}, { targets:-2, render:function(data,type,row,meta){ if(data==1) return "<span class='label label-success radius'>正常</span>"; return "<span class='label label-danger radius'>维护</span>"; } }, { targets:[1,2,3], orderable: false }, ]
交互式:
https://coderexample.com/datatable-responsive-server-side/
reload:
https://datatables.net/reference/api/ajax.reload()
Send request as POST:
Javascript
$('#example').dataTable( {
"ajax": {
"url": "data.json",
"type": "POST"
}
} );
Add data to the request, returnng an object by extending the default data:
$(
'#example'
).dataTable( {
"ajax"
: {
"url"
:
"data.json"
,
"data"
:
function
( d ) {
return
$.extend( {}, d, {
"extra_search"
: $(
'#extra'
).val()
} );
}
}
} );
function datatablessearch()
{
datableCurr.ajax.reload();
}
dataableCurr能用ajax,要注意是大写的DataTable()调用得到DataTables对象,否则用小写dataTable()得到的是juqery对象,没有ajax方法。
$( selector ).DataTable();
- DataTables constructor$( selector ).dataTable().api();
- DataTables jQuery constructor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2015-01-19 Linux epoll
2014-01-19 yii第一个应用blog
2014-01-19 yii基础知识-
2014-01-19 yii基础知识-应用
2014-01-19 yii 的mvc工作流
2013-01-19 Eclipse各版本区别
2013-01-19 在Eclipse中配置Tomcat