Retrieving page Information of jQuery Data Table
Posted By : Tushar Paliwal | 20-Jan-2014
Data Table
DataTable is an object which is used to display data i.e. rows and columns of table in DataSet.which means we can have multiple dataTable in a dataSet.
It provide various functionalities to arrange data in a proper manner like pagination, filteration, sorting, searching etc.which helps developer to make page attractive and easy to maintain.
Pagination
Pagination is a mechanism provided by dataTable which is used to put control over the pages of data shown is the table.There is mainely two type of pagination technique is used by dataTable :
1. two_ button(default)
2. full_members
But we can use the option as per our need.Here two_button is used as default .We can provide another option by initializing sPaginationType to full_members .which will provide us extra buttons to traverse over the pages link like 1,2,3... and first, previous, next, last.
Retrieving current information of page in DataTable
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
};
iStart : It shows the first row index of currently active page .
iEnd : It shows the last row index of currently active page .
iLength : It shows available rows for currently active page which is being mentioned in drop down.
iTotal : It shows total no of rows for dataTable.
iFilteredTotal : It shows total no of filtered rows for dataTable.
iPage : It shows the currently active page index for dataTable.
ITotalPage : It shows the total no of pages.
Customize page information of DataTable page.
$(document).ready(function() {
$('#example').dataTable( {
"sPaginationType": "full_numbers",
"iDisplayLength": 3,
"bFilter": false,
"aLengthMenu": [[10, 25, 50, -1], [10, 20, 30, "All"]]
} );
} );
iPaginationType : It is other option which is used to display pages link like 1,2,3... and first, previous, next, last.
iDisplayLenth : It shows the no of available rows for currently active page .
sFilter : It provides facility to make search field enable and disable by default it is true.
aLengthMenu : It is used to set drop down options by using array.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Tushar Paliwal
Tushar is a developer with experience in Groovy and Grails , Spring and enterprise Java Technologies.