1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-11-29 11:24:10 +01:00

Update - example: Add data option to SSP pipeling

- The piplining example didn't have any method to submit additional data
  with the Ajax request, other than to modify the library function.

- This commit adds a `data` option which provides the same functionality
  as the `ajax.data` option in DataTables - i.e. it can be an object or
  function
This commit is contained in:
Allan Jardine 2014-03-04 08:52:05 +00:00
parent c5d86ea157
commit 8186f9378c
2 changed files with 39 additions and 5 deletions

View File

@ -1 +1 @@
ef495a01f6e667888e890661e4abf990014a55d6
d4aebc0ff333090bf3b1cf840ceeabeb15595203

View File

@ -25,8 +25,10 @@
$.fn.dataTable.pipeline = function ( opts ) {
// Configuration options
var conf = $.extend( {
pages: 5, // number of pages to cache
url: '' // script url
pages: 5, // number of pages to cache
url: '', // script url
data: null // function or object with parameters to send to the server
// matching how `ajax.data` works in DataTables
}, opts );
// Private variables for storing the cache
@ -72,6 +74,21 @@ $.fn.dataTable.pipeline = function ( opts ) {
request.start = requestStart;
request.length = requestLength*conf.pages;
// Provide the same `data` options as DataTables.
if ( $.isFunction ( conf.data ) ) {
// As a function it is executed with the data object as an arg
// for manipulation. If an object is returned, it is used as the
// data object to submit
var d = conf.data( request );
if ( d ) {
$.extend( request, d );
}
}
else if ( $.isPlainObject( conf.data ) ) {
// As an object, the data given extends the default
$.extend( request, conf.data );
}
settings.jqXHR = $.ajax( {
"url": conf.url,
"data": request,
@ -183,8 +200,10 @@ $(document).ready(function() {
$.fn.dataTable.pipeline = function ( opts ) {
// Configuration options
var conf = $.extend( {
pages: 5, // number of pages to cache
url: '' // script url
pages: 5, // number of pages to cache
url: '', // script url
data: null // function or object with parameters to send to the server
// matching how `ajax.data` works in DataTables
}, opts );
// Private variables for storing the cache
@ -230,6 +249,21 @@ $.fn.dataTable.pipeline = function ( opts ) {
request.start = requestStart;
request.length = requestLength*conf.pages;
// Provide the same `data` options as DataTables.
if ( $.isFunction ( conf.data ) ) {
// As a function it is executed with the data object as an arg
// for manipulation. If an object is returned, it is used as the
// data object to submit
var d = conf.data( request );
if ( d ) {
$.extend( request, d );
}
}
else if ( $.isPlainObject( conf.data ) ) {
// As an object, the data given extends the default
$.extend( request, conf.data );
}
settings.jqXHR = $.ajax( {
"url": conf.url,
"data": request,