Multi filtering system problem

Multi filtering system problem

dfigueiradfigueira Posts: 15Questions: 3Answers: 0

Hi guy's,

I've created an "extension" to the datatables to project my needs.
It basically consists on a box with many types of filters. Multi checkbox's that are added to a regex string for search purposes, many types of calculations depending on the type of data to check if it's null, bigger than etc to add the result to the regex string and the possibility of having an external filtering data coming from multiple charts. Basicly I'm getting the current data saved at the local storage and editing the search string's from the correct columns.

All this seems pretty "doable", except a problem I'm having.

When loading the chart from the local storage - as explained in the manual from here - it comes everything correct but I can't access in any way to the cache from the search, so that I can create the filtering system.

From what I've understood, when doing:
table.column(table.colReorder.transpose(colIdx)).cache('search').unique().sort().each(function (d) {

The unique() and sort() would "emulate" a change to the datatable, so there should always be cache at the search.
Isn't this the main purpose, like it's explained on the manual?

Thank you all.

Replies

  • allanallan Posts: 63,844Questions: 1Answers: 10,518 Site admin

    That does look like it should work. Can you link to a page showing the issue so I can take a look please?

    Thanks,
    Allan

  • dfigueiradfigueira Posts: 15Questions: 3Answers: 0

    Well I don't have a link since the page I'm working on is local and I have no way to export it, but here is the what I'm doing

    var tableContainer = $('.datatable-reorder');
    
    tableContainer.each(function () {
        var container = $(this),
            table = container.DataTable({
                "rowReorder": true,
                "processing": true,
                stateSave: true,
                stateSaveCallback: function (settings, data) {
                    console.log("state save");
                    localStorage.setItem(settings.sTableId, JSON.stringify(data));
                },
                stateLoadCallback: function (settings) {
                    console.log("state load");
                    // JSON.parse(localStorage.getItem(tableContainer.attr("ID")));
                }
            });
    
        table.columns().flatten().each(function (colIdx) {
    
            var formContainer = container.find(("[data-column-index='" + colIdx + "']")).find("form"),
                list = $("<ul id='checkbox-list' />").insertAfter(formContainer.children("fieldset").eq(0));
    
                table.column(table.colReorder.transpose(colIdx)).cache('search').unique().sort().each(function (d) {
                    list.append($('<li><fieldset><label for="' + d + '">' + d + '<input type="checkbox" id="' + d + '" name="' + d + '" value="' + d + '"/></label></fieldset></li>'));
                });
    
            });
    
    });
    

    There may be any unclosed bracket but it's closed on my side. It's only because I'm doing a lot of code between these actions, but everything is commented out so only this piece is being run.

    Any thoughts on what could cause the problem?

    Thank you

  • dfigueiradfigueira Posts: 15Questions: 3Answers: 0

    Any thoughts on these?

    Thank you

  • allanallan Posts: 63,844Questions: 1Answers: 10,518 Site admin

    I don't immediately see the issue from that code I'm afraid. I'd really need a test case on JSFiddle or similar to be able to help.

    Allan

  • dfigueiradfigueira Posts: 15Questions: 3Answers: 0

    Just to be sure, this part .unique().sort() always guarantees that the cache will work, right?

  • allanallan Posts: 63,844Questions: 1Answers: 10,518 Site admin

    No. The only way of being sure that the cache will work is to know that that data has been requested by DataTables already (i.e. its done a filter).

    Rather than using the cache I wonder if you might be better served using the cells().render() method and getting a column of the display data that way - e.g. table.cells( null, 0 ).render('display') to get the display data for column index 0.

    Allan

  • dfigueiradfigueira Posts: 15Questions: 3Answers: 0

    That worked allan. I recalled that the unique and sort would work out the cache but thank you!

This discussion has been closed.