How to disable a filter while exporting?

How to disable a filter while exporting?

markzzzmarkzzz Posts: 49Questions: 8Answers: 1

Hi,

I've a resultset of N rows, which I display using a filter (since some rows need to be just exported):

$.fn.dataTable.ext.search.push(
            function (settings, data, dataIndex, originalData) {
                var selectedValue = 1;
                var dataValue = parseInt(originalData["IsLastLevel"]) || 0;

                if (isNaN(selectedValue) || dataValue == selectedValue) {
                    return true;
                }

                return false;
            }
        );

So I get M (<N) rows displayed. Not, when I export, I'd like to include them in the export. How can I disable the filter only for export? Or how would you manage this situation? (also because the "info-box" alert the user that there are "more" rows, which is not so good)

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    See if this example helps:
    https://datatables.net/reference/type/selector-modifier

    I think you will need to use search: 'none' to export all rows.

    Kevin

  • markzzzmarkzzz Posts: 49Questions: 8Answers: 1

    @kthorngren: the problem is that this will disable "all filters" I have, not only that one specific. That's the major problem...

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    You can use buttons.buttons.action for this. See the last example for how to do this and execute the clicked export button.

    Kevin

  • markzzzmarkzzz Posts: 49Questions: 8Answers: 1

    I think I've got this way:

        action: function (e, dt, button, config) {
            // show all
            $('#IsLastLevel').val(NaN);
            dtGrid.draw();
    
            $.fn.dataTable.ext.buttons.excelHtml5.action.call(dt.button(button), e, dt, button, config);
    
            // reapply filter
            $('#IsLastLevel').val(1);
            dtGrid.draw();
        }
    

    So: when I export, I disable the specifed filter, redraw, than export. When its finished, I restore filter, and I redraw table.

    A bit of overhead, but I think that's the only solution?

This discussion has been closed.