Special Filter Operations on Server side - State Saving Issue
Special Filter Operations on Server side - State Saving Issue
tapsboy
Posts: 11Questions: 0Answers: 0
So, what I want to do is filter datatables on serverside for conditions like
Amount < 10000 or
Date > 04/12/2011
Those specific operations will be carried out in SQL, which will be constructed on the server-side by the programming language, once the individual parts are available.
Datatables is already capable of sending sSearch_0: 10000 to the server
I added another property to manage the filter operation sSearchOp_0: lt (less than) using the following code
Since I have this on the server side: 0 = Amount, sSearch_0= 10000, sSearchOp_0='lt'
I can build SQL like Amount < 10000.
In order to achieve this, first I do this:
[code]
var option = $('select option:selected', $(this)).val();
oSettings.aoPreSearchCols[colToFilter].sSearchOp = option;
[/code]
and then added this bit of code to the fnServerData
[code]
'fnServerData': function (sSource, aoData, fnCallback){
var filter_cols = this.fnSettings().aoPreSearchCols;
$.each(filter_cols, function(index,value){
aoData.push({ "name": "sSearchOp_"+index, "value": value.sSearchOp });
});
$.ajax({
"dataType": 'json',
"type": 'POST',
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
[/code]
This helps me obtain the filtered results as per the criteria supplied. So far so good.
However, I am unable to save this extra variable sSearchOp in the cookie, in spite of writing this code:
[code]
'fnStateSaveCallback': function(oSettings, sValue){
var oData = JSON.parse( sValue+"}" );
var filter_cols = oSettings.aoPreSearchCols;
$.each(filter_cols, function(index,value){
oData.aaSearchCols[index][2] = value.sSearchOp;
});
return JSON.stringify(oData).slice( 0, -1 );
}
[/code]
What happens is that 'fnStateSaveCallback' gets called twice, as I am using the Col-reorder plugin, which re-constructs sValue and saves it to Cookie.
Is there something that I should do differently to make this happen?
Amount < 10000 or
Date > 04/12/2011
Those specific operations will be carried out in SQL, which will be constructed on the server-side by the programming language, once the individual parts are available.
Datatables is already capable of sending sSearch_0: 10000 to the server
I added another property to manage the filter operation sSearchOp_0: lt (less than) using the following code
Since I have this on the server side: 0 = Amount, sSearch_0= 10000, sSearchOp_0='lt'
I can build SQL like Amount < 10000.
In order to achieve this, first I do this:
[code]
var option = $('select option:selected', $(this)).val();
oSettings.aoPreSearchCols[colToFilter].sSearchOp = option;
[/code]
and then added this bit of code to the fnServerData
[code]
'fnServerData': function (sSource, aoData, fnCallback){
var filter_cols = this.fnSettings().aoPreSearchCols;
$.each(filter_cols, function(index,value){
aoData.push({ "name": "sSearchOp_"+index, "value": value.sSearchOp });
});
$.ajax({
"dataType": 'json',
"type": 'POST',
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
[/code]
This helps me obtain the filtered results as per the criteria supplied. So far so good.
However, I am unable to save this extra variable sSearchOp in the cookie, in spite of writing this code:
[code]
'fnStateSaveCallback': function(oSettings, sValue){
var oData = JSON.parse( sValue+"}" );
var filter_cols = oSettings.aoPreSearchCols;
$.each(filter_cols, function(index,value){
oData.aaSearchCols[index][2] = value.sSearchOp;
});
return JSON.stringify(oData).slice( 0, -1 );
}
[/code]
What happens is that 'fnStateSaveCallback' gets called twice, as I am using the Col-reorder plugin, which re-constructs sValue and saves it to Cookie.
Is there something that I should do differently to make this happen?
This discussion has been closed.