How to store the state info only for particular actions like colreorder,column visibility and sort

How to store the state info only for particular actions like colreorder,column visibility and sort

Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

I am able to save the state of user using stateSaveCallback . But when I click on row and going to the next page also its performing stateSaveCallback function. I want control that.

Pls help.

Replies

  • allanallan Posts: 56,888Questions: 1Answers: 9,042 Site admin

    Use stateSaveParams to delete the items you don't want from the state object.

    Allan

  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

    I just click on a row but its calling stateSaveCallback function 2 time I am not understanding.
    please help me.

    "stateSaveCallback": function (settings, data) {
    for (const column in data.columns) { //I do not want to save the search criteria to the database. It could make the string too long
    delete data.columns[column].search;
    }
    delete data.select;

    var tableListJSON = {};
    var tableListJSON = JSON.stringify(data);

    $.ajax( {
      "url": extract_url('/rest/state_save'),
        data: {
    
            tableList : tableListJSON,
            tableName : 'ZonesTable',
            loggedInUser : loggedInUser,
                "_csrf": CSRF_TOKEN
            },
      "dataType": "json",
      "type": "POST",
      "success": function () {}
    } );
    

    },

    stateSaveParams: function (settings, data) {
    delete data.search;
    },

  • kthorngrenkthorngren Posts: 16,827Questions: 25Answers: 3,989

    I just click on a row but its calling stateSaveCallback function 2 time I am not understanding.

    Looks like you are using the Select extension. When you click a row and its selected or deselected then stateSave will update / save the current state. Same with other actions on the table. This is why you see it called many times. As Allan said if you don't want to save the sate of certain things like search then use stateSaveParams to remove those options.

    Kevin

  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0
    edited August 8

    I have added data.select in statesaveparams aas mentioned below

    stateSaveParams: function (settings, data) {
    delete data.search;
    delete data.select;
    },

    In this data the select method was not there i think.

    But still its calling save state function many times.

    And its not going to backed as selected row also.And I don't want to save also.

  • Madhavi BhimisettyMadhavi Bhimisetty Posts: 11Questions: 1Answers: 0

    If I remove select: true , then I am not able to perform CRUD operations like create and edit.

    Please help me.

  • kthorngrenkthorngren Posts: 16,827Questions: 25Answers: 3,989

    I built a test case to show that delete data.select; works. You are right it doesn't work. The test case shows the object is deleted but when the state is loaded the select object is there. Not sure if @allan considers this a bug but it seems the StateSave library saves the select state after stateSaveParams.
    http://live.datatables.net/qoluroce/1/edit

    You can remove the StateSave information using stateLoadParams. The example shows this.

    Kevin

Sign In or Register to comment.