Get the id of the respective Data Table

Get the id of the respective Data Table

rf1234rf1234 Posts: 2,982Questions: 87Answers: 421

I implemented my own state saving solution with state saving on the server via ajax. I save user_id, data table id and other attributes.

In "stateSaveCallback" and "stateLoadCallback" there is a "settings" parameter that allows me to get the data tables id (e.g. "#myDataTable").

stateSaveCallback: function(settings,data) {
    var tableId = settings.nTable.id; //id of the data table
    $.ajax({
        type: "POST",
        url: 'actions.php?action=saveState',
        data: {
            userId:     currentUserId,
            dataTable:  tableId,
            webPage:    webPage,
            width:      percent,
            values:     JSON.stringify(data)
        }
    });
},

I also have a button to delete the saved state. I want the button to be reusable and hence need to get the id of the respective data table the same way as above. But I couldn't find a way to do this - which forces me to have an individual button for each data table.

Any idea?

{   name:   "deleteState",
    text:   function () { return lang === 'de' ? 'Layout Reset' : 'Reset Layout' },
    action: function ( e, dt, node, config ) {
        $.ajax({
            type: "POST",
            url: 'actions.php?action=deleteState',
            data: {
                userId:     currentUserId,
                dataTable:  "tblSubReg",
                webPage:    webPage
            },
            success: function () {
                window.location.reload(true);
            }
        });
    }
},

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,982Questions: 87Answers: 421

    I got this work around now using the "node" parameter above:

    var tblId = node[0].offsetParent.id.split("_")[0];
    

    Pretty ugly though. Any idea?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓
    dt.table().node().id
    

    will do it there - using the table().node() method of the dt (API instance) passed in.

    Allan

Sign In or Register to comment.