Filters do not work at the same time

Filters do not work at the same time

lvklvk Posts: 2Questions: 1Answers: 0
edited July 2017 in Free community support

Hello, 8 filters for 4 columns. But do not work at the same time. Please tell me how to solve the problem?

$.fn.dataTable.ext.search.push(
            function (settings, data, dataIndex) {
                let startF, endF, val;
                if (Raiko.SEO.filterType == "Sum") {
                    startF = parseInt($('#startSum').val(), 10);
                    endF = parseInt($('#endSum').val(), 10);
                    val = parseFloat(data[1]) || 0;
                }
                if (Raiko.SEO.filterType == "Traffic") {
                    startF = parseInt($('#startTraffic').val(), 10);
                    endF = parseInt($('#endTraffic').val(), 10);
                    val = parseFloat(data[2]) || 0;

                }
                if (Raiko.SEO.filterType == "Percent") {
                    startF = parseInt($('#startPercent').val(), 10);
                    endF = parseInt($('#endPercent').val(), 10);
                    val = parseFloat(data[3]) || 0;
                }
                if (Raiko.SEO.filterType == "Position") {
                    startF = parseInt($('#startPosition').val(), 10);
                    endF = parseInt($('#endPosition').val(), 10);
                    val = parseFloat(data[4]) || 0;
                }

                if ((isNaN(startF) && isNaN(endF)) ||
                    (isNaN(startF) && val <= endF) ||
                    (val >= startF && isNaN(endF)) ||
                    (val >= startF && val <= endF)) {
                    return true;
                }
                return false;
            }
        );

Answers

  • lvklvk Posts: 2Questions: 1Answers: 0

    How to know if a filtered line? I wanted to compare the elements in the filtered array with original. But it's not working:

    $.fn.dataTable.ext.search.push(
                function (settings, data, dataIndex) {
                    let sData = $('#dataTable').DataTable().rows({ search: 'applied' }).data().toArray();
                    for (var i = 0, iLen = sData.length; i < iLen; i++) {
                        if (data[0] === sData[i][0]) {
                            let startF, endF, val;
                            if (Raiko.SEO.filterType == "Sum") {
                                startF = parseInt($('#startSum').val(), 10);
                                endF = parseInt($('#endSum').val(), 10);
                                val = parseFloat(data[1]) || 0;
                            }
                            if (Raiko.SEO.filterType == "Traffic") {
                                startF = parseInt($('#startTraffic').val(), 10);
                                endF = parseInt($('#endTraffic').val(), 10);
                                val = parseFloat(data[2]) || 0;
    
                            }
                            if (Raiko.SEO.filterType == "Percent") {
                                startF = parseInt($('#startPercent').val(), 10);
                                endF = parseInt($('#endPercent').val(), 10);
                                val = parseFloat(data[3]) || 0;
                            }
                            if (Raiko.SEO.filterType == "Position") {
                                startF = parseInt($('#startPosition').val(), 10);
                                endF = parseInt($('#endPosition').val(), 10);
                                val = parseFloat(data[4]) || 0;
                            }
    
                            if ((isNaN(startF) && isNaN(endF)) ||
                                (isNaN(startF) && val <= endF) ||
                                (val >= startF && isNaN(endF)) ||
                                (val >= startF && val <= endF)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            );
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    How to know if a filtered line?

    It shouldn't appear in the table. Another option would be to use the API to get the filtered out rows: table.rows( { search: false } ).nodes()

    Hello, 8 filters for 4 columns. But do not work at the same time. Please tell me how to solve the problem?

    Happy to take a look at a test case showing the issue.

    Allan

This discussion has been closed.