Datatable1.10: Server disconnected page, datatable1.10 page
Next, the new feature of ableable1.10 in the previous article. For work requirements, We Need To paging the server.
I still take the Code directly .. Add comments to the code .. If you have any questions, give me some advice...
$ (Document). ready (function (){
Var table = $ ('# example'). DataTable ({
"Columns": _ tableCols,
"CreatedRow": xxxxxx, // function name
"Processing": true, // when the data is not fully loaded at once, the page displays loading in progress.
"ServerSide": true, // if it is set to true, the server page is displayed.
"PagingType": "full_numbers", // display form of the paging button
"Paging": true, // if it is FALSE, all data is displayed on a page.
"Ajax ":{
"Url": "xxxx/query ",
"Type": 'post ',
"Data": function (d ){
D. orderby = "position ";
},
"DataSrc": function (json ){
Return json. records;
},
},
});
});
// The above js Code is all written. If you need to add other attributes, such as lengthMenu, etc... See the server side processing URL for: http://datatables.net/manual/server-side
I use the springmvc framework. Therefore, the returned object must contain the recordsFiltered and recordsTotal long integer parameters. Otherwise, an error is reported (for example, the number of Showing 1 to 10 of 57 entries is NaN ). For more information, see the json data source on the official website. Therefore, the returned object should contain two parameters.
// RecordsFiltered is the total number of records in the data set after filtering
Private long recordsFiltered = 0;
// Total number
Private long recordsTotal = 0;
If you have any questions, please leave a message ....
The data source does not support data paging on the server.
F (! This. IsPostBack)
{
String newsTypeID = Request. QueryString ["TypeID"]. ToString ();
SqlConnection con = DB. createConnection ();
Con. Open ();
String sqlstr = "select * from newsTile where newsTypeID = '" + newsTypeID + "'";
SqlDataAdapter da = new SqlDataAdapter (sqlstr, con );
DataSet ds = new DataSet ();
Da. Fill (ds );
GridView1.DataSource = ds. Tables [0]. DefaultView;
GridView1.DataBind ();
}
That's all. You can see it clearly.
Good paging with server language or good JavaScript
Even without refreshing pages in ajax
It is also the frontend display of the page output data of background processing.
Instead of using js to implement Paging
You cannot put all the data on the front-end and use js to split the data. This means that a large amount of data is dead.