From d4a1028a1db07568697419787d3905d2c014fdf4 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Fri, 29 Nov 2013 11:36:03 +0000 Subject: [PATCH] Dev fix - Full backwards compatiblity with fnServerParams with array syntax paraneter names - Data added using fnServerParams with array syntax had different behaviour in 1.10 from 1.9. In 1.9 jQuery would create an array for us, but in 1.10 before we create an object first, we need to create that array ourselves. So the following code had different behaviour: "sAjaxSource": "data/arrays.txt", "fnServerParams": function ( d ) { d.push( {name: 'somekey[]', value: 'somevalue1'}, {name: 'somekey[]', value: 'somevalue2'} ); } In 1.10 it would have sent `somekey[] = somevalue2` but 1.9 would have sent both as part of an array. To maintain full compatiblity with 1.9 we need to convert this syntax to an array - this commit does that. I was concerned about using parameters in the brackets, but jQuery only searches for `[]` when performing this conversion. We could use $.param and then decode the created query string, which would be absolutely 100% comaptible, but would involve additional code and I think this method provides that 100% compatiblity from reading the jQuery code), and its shorter. --- .datatables-commit-sync | 2 +- media/js/jquery.dataTables.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index ec1f0f7c..a11246af 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -667ebcafa99f93bb2be04892ec8be75161a04921 +a3f57e46e1a0429dc63527ce1ea125925226eaa3 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 12aabd40..1646d7f1 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -2211,8 +2211,23 @@ // Convert to object based for 1.10+ if using the old scheme if ( data && data.__legacy ) { var tmp = {}; + var rbracket = /(.*?)\[\]$/; + $.each( data, function (key, val) { - tmp[val.name] = val.value; + var match = val.name.match(rbracket); + + if ( match ) { + // Support for arrays + var name = match[0]; + + if ( ! tmp[ name ] ) { + tmp[ name ] = []; + } + tmp[ name ].push( val.value ); + } + else { + tmp[val.name] = val.value; + } } ); data = tmp; }