Re-rendering cells upon column search and filter

Re-rendering cells upon column search and filter

guillochonguillochon Posts: 56Questions: 19Answers: 0

Hi, I'm currently re-rendering cells when a user types in text into either the filter or column search fields. This works wonderfully except for the rows that appeared on the first page, they appear to be cached and the rendering function is ignored. Is there a way to clear the render cache when a user searches the table?

Here is the rendering function I am currently using:

function nameSwitcher ( data, type, row ) {
    if ( type === 'display' ) {
        var idObj = document.getElementById("name");
        var filterTxt = jQuery('.dataTables_filter input').val().toUpperCase();
        var idObjTxt = idObj.value.toUpperCase();
        var txts = Array(filterTxt, idObjTxt);
        for (var t = 0; t < txts.length; t++) {
            var txt = txts[t];
            if (txt !== "") {
                if (row.alias.length > 1) {
                    var aliases = getAliases(row);
                    var primaryname = row.name;
                    for (var a = 0; a < aliases.length; a++) {
                        if (aliases[a].toUpperCase().indexOf(txt) !== -1) {
                            primaryname = aliases[a];
                            break;
                        }
                    }
                    var otheraliases = Array();
                    for (var a = 0; a < aliases.length; a++) {
                        if (aliases[a].toUpperCase() === primaryname.toUpperCase()) {
                            continue;
                        }
                        otheraliases.push(aliases[a]);
                    }
                    return "<div class='tooltip'><a href='https://sne.space/sne/" + row.name.replace(/\//g,'_') +
                        "/' target='_blank'>" + primaryname + "</a><span class='tooltiptext'>" + otheraliases.join(', ') + "</span></div>";
                } else {
                    return "<a href='https://sne.space/sne/" + row.name.replace(/\//g,'_') + "/' target='_blank'>" + row.name + "</a>";
                }
            }
        }
        return data;
    }
    return data;
}

Thanks!

Answers

  • guillochonguillochon Posts: 56Questions: 19Answers: 0

    OK I almost have this figured out. I was able to invalidate the visible cells in my column filters, which solves the problem for them.

    However, how do I invalidate the visible rows using the global filter? If I can figure that out then I'm set.

  • guillochonguillochon Posts: 56Questions: 19Answers: 0

    The solution to this is to add the following code to trigger on a search event:

            table.on( 'search.dt', function () {
                table.rows({page:'current'}).invalidate()
            } );
    
  • guillochonguillochon Posts: 56Questions: 19Answers: 0

    The solution to this is to add the following code to trigger on a search event:

            table.on( 'search.dt', function () {
                table.rows({page:'current'}).invalidate()
            } );
    
This discussion has been closed.