ranman0049 / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

bstatesave does not work for number-range #58

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. make a numeric column with "number-range" filter
2. set "bStateSave: true
3. filter the numeric-range column and then refresh your browser

What is the expected output? What do you see instead?
When refreshing, it does not retain the range values.  I expect it to keep them.

What version of the product are you using? On what operating system?
1.4.7, Mac OS X

Please provide any additional information below.

Original issue reported on code.google.com by rha...@gmail.com on 3 Mar 2012 at 9:21

GoogleCodeExporter commented 8 years ago

Original comment by joc...@gmail.com on 6 Mar 2012 at 12:02

GoogleCodeExporter commented 8 years ago
Strangely enough it still filters on refresh but the text value is gone making 
it confusing for end user. Where's the data!

Original comment by gounta...@gmail.com on 27 Jun 2012 at 4:06

GoogleCodeExporter commented 8 years ago
This problem is also occuring on the checkbox filter. It's probably to do with 
the Range and Checkbox selectors being multi-value, and the out-of-the-box 
save/load code not splitting the values and assigning them.

(see http://mvcjquerydatatables.apphb.com/)

Original comment by mcintyre...@gmail.com on 27 Sep 2012 at 12:52

GoogleCodeExporter commented 8 years ago
Any updates on this?  I was able to tweak the checkbox filter logic to make it 
act more like the select-filter, and now it is persisting. But I'm stuck with 
the Range Filter. Looks like oTable.fnSettings().sSearch doesn't keep track of 
even the "From" string?  Not sure how to retrieve the "From" and "To" values to 
restore the filter.  

Also, someone above mentioned that the filter is getting saved but the text 
fields are just not getting repopulated.  For me even the filter doesn't 
persist upon reopening the table (but it works fine for the regular text inputs 
and other filter types). If someone has a fix for this, please post a snippet!  
It would be nice to get this plugin cleaned up a bit for the next drop.

Original comment by KAkkape...@gmail.com on 17 Oct 2012 at 4:35

GoogleCodeExporter commented 8 years ago
For those who come after me: I found the same problem using date-range. It 
appears to be due to the fact that the range search string (e.g. 
"1/1/2013~2/2/2013" for dates) is never successfully saved to 
oTable.fnSettings().aoPreSearchCols[i].sSearch (this is a DataTables variable). 
I have no idea why, the interaction of this plugin with datatables is too 
complex for me to unravel.

Two problems arise from this:
* as noted above, bStateSave doesn't actually save state for ranges
* it's impossible to query the datatables settings for the last submitted query 
- I needed this in order to implement a server-side 'export' feature (needed to 
re-submit the last query)

I fixed the problem by making two changes in jquery.dataTables.columnFilter.js 
(KLUDGES, USE AT YOUR OWN RISK!!!): 

1. Near the bottom of the file, there are these lines:

if (aoData[k].name == "sSearch_" + index)
    aoData[k].value = afnSearch_[j]();

I wrapped the second line in braces and added a line after it to manually force 
the correct value to be pushed to the sSearch variable - as in:

         if (aoData[k].name == "sSearch_" + index) {
            aoData[k].value = afnSearch_[j]();
            // Added this line to force the value in
            oTable.fnSettings().aoPreSearchCols[index].sSearch = aoData[k].value;
         }

This takes care of remembering the date range, but it doesn't re-display it 
after a refresh.

2. In the method 

      function fnCreateDateRangeInput(oTable)

I added some code to retrieve the date range, parse it, and display it. Here's 
my code, I'm sure it has some edge case errors (this is right after the start 
of the method):

         var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch;
         var fromDatePre = '';
         var toDatePre = '';
         if (currentFilter != '' && currentFilter != 'undefined') {
            var arrDates = currentFilter.split("~");
            fromDatePre = arrDates[0];
            toDatePre = arrDates[1];
         }

A few lines down from this I use the two variables to create 'value' parameters 
for the two input elements, as in:

          var from = $('<input type="text" class="date_range_filter" id="' + sFromId + '" rel="' + i + '" value="' + fromDatePre + '"/>');

Note the last attribute, 'value = ...'.

These two changes did it for me.

Original comment by cpc...@gmail.com on 17 Apr 2013 at 4:37