Filter a parent table from a preferences table.

Filter a parent table from a preferences table.

JanNL_FRJanNL_FR Posts: 47Questions: 15Answers: 2

Link to test case: https://campcare.eu/Drill/users.html and https://campcare.eu/Drill/index.html

I want a user to be able to add frequently used preferences to their user account to select a filter that will filter the parent table.
What is the best way to achieve this?

Replies

  • rf1234rf1234 Posts: 2,906Questions: 87Answers: 414
    edited December 2023

    You can use state saving. By default it also saves entries into the search field. So the table will be filtered when the user opens the page again.

    That is the simplest way. I also use predefined column search with buttons. Also works fine.
    https://datatables.net/reference/option/stateSave
    https://datatables.net/reference/api/column().search()

    Here is an example for predefined column search with buttons:

    .....
        buttons: [
            {   extend: "create",       editor: vatQuestionEditor    },
            {   extend: "edit",         editor: vatQuestionEditor    },
            {   extend: "remove",       editor: vatQuestionEditor    },
            {   extend: "vatOption",    className: "btn-showall-color"   },
                        "toggleWidth",
                        "deleteState",
                        "colvis",
            {   text: lang === "de" ? "Alles" : "All",
                action: function ( e, dt, node, config ) {
                    dt.columns("#qaStatus").search("").draw();
                }
            },
            {   text: lang === "de" ? "Nur Test" : "Test only",
                action: function ( e, dt, node, config ) {
                    dt.columns("#qaStatus").search("test version", false, false).draw();
                }
            },
            {   text: lang === "de" ? "Nur Live" : "Live only",
                action: function ( e, dt, node, config ) {
                    dt.columns("#qaStatus").search("live version  ", false, false).draw();
                }
            },
            {   text: lang === "de" ? "Nur vorherige Live" : "Previous Live only",
                action: function ( e, dt, node, config ) {
                    dt.columns("#qaStatus").search(" live version", false, false).draw();
                }
            }
        ]
    });
    
    vatQuestionTable
        .on('init', function (e, settings, json) {
            vatQuestionTable.columns("#qaStatus").search("").draw().columns.adjust();
        })
    
  • JanNL_FRJanNL_FR Posts: 47Questions: 15Answers: 2

    I used the parent child examples and got it working.

    saveState is also a nice to have option. Thanks rf1234

    Jan

Sign In or Register to comment.