bStateSave not storing number/date-ranges in the aoSaerchCols:sSearch object

bStateSave not storing number/date-ranges in the aoSaerchCols:sSearch object

sabricksabrick Posts: 10Questions: 4Answers: 0

I have a datatable that has date & number ranges by which it can be filtered using the jquery-datatables-column-filter plugin.

I have set up the following console log event to show the oData object (the JSON object that is saved upon the StateSave event triggering):

"fnStateSaveParams": function (oSettings, oData) { console.log(oData); }

This exposes the oData object to the console, in which I can read that the aoSearchCols object which stores the text value of the filters being applied to that individual column:

bCaseInsensitive: true
bRegex: false
bSmart: false
sSearch: "filter text"

In the above is an example, the text "filter text" is being saved and is re-applied to the table upon loading. However the "sSearch" object does not seem to store data in it for number and date-range columns; in other words: the sSearch object for number/date-ranges is always blank. Could anyone explain a work around for this?

Answers

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    Among many other feature my yadcf plugin support state saving for all its 8 (and counting) filter types , you can see the following showcase example with state saving and range number slider filter http://yadcf-showcase.appspot.com/DOM_source_chosen.html

  • sabricksabrick Posts: 10Questions: 4Answers: 0

    Great job with this Daniel.

    Having a bit of problem with it though:

    I've successfully installed your plugin and I'm able to use it, and I can see where you add the yadcfState object to the oData object to hold range information. However, when I try to load the information I get an error inside the function:

    function addRangeNumberFilterCapability(table_selector_jq_friendly, fromId, toId, col_num, ignore_char) 
    
        $.fn.dataTableExt.afnFiltering.push(
            function (oSettings, aData, iDataIndex) {
                var min = document.getElementById(fromId).value,
    

    It crashes here where it says "cannot read 'value' of null

    It looks like it's trying to get the min-value from the value-attribute on the "fromId" element, and I'm guessing it was never filled in.

    This might have to do with how I'm loading the saveState information. I see some people set bServerSide = true and then have an associated ajax call to get the table. However I load the data in by invoking the fnStateLoad event.

                                "fnStateLoad": function (oSettings) {
                                    var o;
                                    $.ajax({
                                        type: "POST",
                                        url: "Default.aspx/_getReportSetting",
                                        data: '{report: "' + currentReport + '", settingsName: "' + settingsName + '" }',
                                        contentType: "application/json; charset=utf-8",
                                        dataType: "json",
                                        async: false,
                                        success: function (response) {
                                            o = JSON.parse(response.d)
                                            console.log(o);
                                        },
                                        failure: function (response) {
                                        }
                                    });
    
                                    return o
                                },
    

    Any ideas?

  • sabricksabrick Posts: 10Questions: 4Answers: 0

    After working on it for awhile it seems that bServerSide must be enabled.

    I don't have this enabled since I load/save oData parameters manually by invoking the fnStateLoad & fnStateSave methods, is there anyway to get your stuff working without bServerSide enabled?

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    I'm not a datatables pro, but I know that bStateSave and bServerSide are not related to each other , bServerSide moves all your datatables logic (sorting/filtering/pagination etc.. to server and bStateSave stores your filtering / sorting / pagination etc on client browser , so those two shouldn't even be used together (IMO), I have never used the fnStateLoad, but maybe you need to double check/ confirm that you are using it properly and that it is the right way to achieve your goal. Regarding the null error in the following yadcf line:

    var min = document.getElementById(fromId).value,

    It will happen when the element with the id that being hold by the fromId was never created (added to the DOM) and for some reason the table was drawn and is trying to do filtering

    You can try and replace that line with this one

    min = document.getElementById(fromId) !== null ? document.getElementById(fromId).value : "",

    and do the same null check for the other problematic code line.

This discussion has been closed.