mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-19 17:54:14 +01:00
New: Server-side processing parameters update
- The server-side processing parameters used by DataTables 1.9 are very ugly, and rather arkward to work with, so in keeping with the camcelCase approach of 1.10 and its general monderisation, when using the `ajax` option to set the ajax url for data, DataTables server-side processing will now use a much more modern method of telling the server what data is required - specifically using arrays and objects in neatly formatted data. - The old 1.9 method is invoked if sAjaxSource is used to set the ajax url, or if $.fn.dataTable.ext.legacy.ajax is set to true. As such, this change should be fully backwards compatible since `ajax` is a new option in 1.10. - This new ability adds 334 bytes to the min file, primarily, because the old method is retained (using just the new method would actually reduce the size slightly).
This commit is contained in:
parent
9d642814cc
commit
8f975060d8
@ -1 +1 @@
|
||||
d01d20a4577a4a1c796cdbd2510e71f1c13b0e62
|
||||
f3bb71cfed8f31c1cc4fcf797efde0ba5246ac78
|
||||
|
138
media/js/jquery.dataTables.js
vendored
138
media/js/jquery.dataTables.js
vendored
@ -1915,12 +1915,14 @@
|
||||
// Compatibility with 1.9-, allow fnServerData and event to manipulate
|
||||
_fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [data] );
|
||||
|
||||
// Convert to object based for 1.10+
|
||||
var tmp = {};
|
||||
$.each( data, function (key, val) {
|
||||
tmp[val.name] = val.value;
|
||||
} );
|
||||
data = tmp;
|
||||
// Convert to object based for 1.10+ if using the old scheme
|
||||
if ( data && data.__legacy ) {
|
||||
var tmp = {};
|
||||
$.each( data, function (key, val) {
|
||||
tmp[val.name] = val.value;
|
||||
} );
|
||||
data = tmp;
|
||||
}
|
||||
|
||||
var ajaxData;
|
||||
var ajax = oSettings.ajax;
|
||||
@ -2021,64 +2023,103 @@
|
||||
|
||||
|
||||
/**
|
||||
* Build up the parameters in an object needed for a server-side processing request
|
||||
* Build up the parameters in an object needed for a server-side processing
|
||||
* request. Note that this is basically done twice, is different ways - a modern
|
||||
* method which is used by default in DataTables 1.10 which uses objects and
|
||||
* arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
|
||||
* the sAjaxSource option is used in the initialisation, or the legacyAjax
|
||||
* option is set.
|
||||
* @param {object} oSettings dataTables settings object
|
||||
* @returns {bool} block the table drawing or not
|
||||
* @memberof DataTable#oApi
|
||||
*/
|
||||
function _fnAjaxParameters( settings )
|
||||
{
|
||||
var columns = settings.aoColumns;
|
||||
var columnCount = columns.length;
|
||||
var features = settings.oFeatures;
|
||||
var preSearch = settings.oPreviousSearch;
|
||||
var preColSearch = settings.aoPreSearchCols;
|
||||
var i, data = [], mDataProp;
|
||||
var
|
||||
columns = settings.aoColumns,
|
||||
columnCount = columns.length,
|
||||
features = settings.oFeatures,
|
||||
preSearch = settings.oPreviousSearch,
|
||||
preColSearch = settings.aoPreSearchCols,
|
||||
i, data = [], dataProp, column, columnSearch,
|
||||
sort = _fnSortFlatten( settings ),
|
||||
displayStart = settings._iDisplayStart,
|
||||
displayLength = features.bPaginate !== false ?
|
||||
settings._iDisplayLength :
|
||||
-1;
|
||||
|
||||
var param = function ( name, value ) {
|
||||
data.push( { 'name': name, 'value': value } );
|
||||
};
|
||||
|
||||
// DataTables 1.9- compatible method
|
||||
param( 'sEcho', settings.iDraw );
|
||||
param( 'iColumns', columnCount );
|
||||
param( 'sColumns', _pluck( columns, 'sName' ).join(',') );
|
||||
param( 'iDisplayStart', settings._iDisplayStart );
|
||||
param( 'iDisplayLength', settings.oFeatures.bPaginate !== false ?
|
||||
settings._iDisplayLength : -1
|
||||
);
|
||||
param( 'iDisplayStart', displayStart );
|
||||
param( 'iDisplayLength', displayLength );
|
||||
|
||||
// DataTables 1.10+ method
|
||||
var d = {
|
||||
draw: settings.iDraw,
|
||||
columns: [],
|
||||
sort: [],
|
||||
start: displayStart,
|
||||
length: displayLength,
|
||||
filter: {
|
||||
value: preSearch.sSearch,
|
||||
regex: preSearch.bRegex
|
||||
}
|
||||
};
|
||||
|
||||
for ( i=0 ; i<columnCount ; i++ ) {
|
||||
mDataProp = columns[i].mData;
|
||||
param( "mDataProp_"+i, typeof mDataProp==="function" ? 'function' : mDataProp );
|
||||
column = columns[i];
|
||||
columnSearch = preColSearch[i];
|
||||
dataProp = typeof column.mData=="function" ? 'function' : column.mData ;
|
||||
|
||||
d.columns.push( {
|
||||
data: dataProp,
|
||||
name: column.sName,
|
||||
searchable: column.bSearchable,
|
||||
sortable: column.bSortable,
|
||||
filter: {
|
||||
value: columnSearch.sSearch,
|
||||
regex: columnSearch.bRegex
|
||||
}
|
||||
} );
|
||||
|
||||
param( "mDataProp_"+i, dataProp );
|
||||
|
||||
if ( features.bFilter ) {
|
||||
param( 'sSearch_'+i, columnSearch.sSearch );
|
||||
param( 'bRegex_'+i, columnSearch.bRegex );
|
||||
param( 'bSearchable_'+i, column.bSearchable );
|
||||
}
|
||||
|
||||
if ( features.bSort ) {
|
||||
param( 'bSortable_'+i, column.bSortable );
|
||||
}
|
||||
}
|
||||
|
||||
/* Filtering */
|
||||
$.each( sort, function ( i, val ) {
|
||||
d.sort.push( { column: val.col, dir: val.dir } );
|
||||
|
||||
param( 'iSortCol_'+i, val.col );
|
||||
param( 'sSortDir_'+i, val.dir );
|
||||
} );
|
||||
|
||||
if ( features.bFilter ) {
|
||||
param( 'sSearch', preSearch.sSearch );
|
||||
param( 'bRegex', preSearch.bRegex );
|
||||
|
||||
for ( i=0 ; i<columnCount ; i++ ) {
|
||||
param( 'sSearch_'+i, preColSearch[i].sSearch );
|
||||
param( 'bRegex_'+i, preColSearch[i].bRegex );
|
||||
param( 'bSearchable_'+i, columns[i].bSearchable );
|
||||
}
|
||||
}
|
||||
|
||||
/* Sorting */
|
||||
if ( features.bSort ) {
|
||||
var aaSort = _fnSortFlatten( settings );
|
||||
|
||||
for ( i=0 ; i<aaSort.length ; i++ ) {
|
||||
param( 'iSortCol_'+i, aaSort[i].col );
|
||||
param( 'sSortDir_'+i, aaSort[i].dir );
|
||||
}
|
||||
param( 'iSortingCols', aaSort.length );
|
||||
|
||||
for ( i=0 ; i<columnCount ; i++ ) {
|
||||
param( 'bSortable_'+i, columns[i].bSortable );
|
||||
}
|
||||
param( 'iSortingCols', sort.length );
|
||||
}
|
||||
|
||||
return data;
|
||||
data.__legacy = true;
|
||||
return settings.sAjaxSource || DataTable.ext.legacy.ajax ?
|
||||
data : d;
|
||||
}
|
||||
|
||||
|
||||
@ -12690,13 +12731,30 @@
|
||||
* anything other than a plug-in (and even then, try to avoid if possible).
|
||||
* The internal function may change between releases.
|
||||
*
|
||||
* externally
|
||||
* @type object
|
||||
* @default {}
|
||||
*/
|
||||
internal: {},
|
||||
|
||||
|
||||
/**
|
||||
* Legacy configuration options. Enable and disable legacy options that
|
||||
* are available in DataTables.
|
||||
*
|
||||
* @type object
|
||||
*/
|
||||
legacy: {
|
||||
/**
|
||||
* Enable / disable DataTables 1.9 compatible server-side processing
|
||||
* requests
|
||||
*
|
||||
* @type boolean
|
||||
* @default false
|
||||
*/
|
||||
ajax: false
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Pagination plug-in methods.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user