From 8186f9378cfb36498ecb91db366340fff062fff9 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 4 Mar 2014 08:52:05 +0000 Subject: [PATCH] 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 --- .datatables-commit-sync | 2 +- examples/server_side/pipeline.html | 42 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 78baf4de..46e77635 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -ef495a01f6e667888e890661e4abf990014a55d6 +d4aebc0ff333090bf3b1cf840ceeabeb15595203 diff --git a/examples/server_side/pipeline.html b/examples/server_side/pipeline.html index e94620c5..ea6b13b6 100644 --- a/examples/server_side/pipeline.html +++ b/examples/server_side/pipeline.html @@ -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,