Questions about savedStates config - update not calling Ajax
Questions about savedStates config - update not calling Ajax

Hello,
Issues I encountered with savedStates button pushed to finally make a post here. I'm sure I dont quite understand how savedStates works internally. The main issue I'm having is that the update button in the savedStates dropdown doesnt execute the ajax function. Instead it updates selected configuration in the browser (locally?) but doesnt send it via ajax.
Another question I have is, can we determine which state is active by some value returned in the object from ajax call or the imput object in callback?
Last thing is could you generally check if I'm correctly processing the logic of savedStates in below function? In general is there something I implemented that might not work as expected?
{
extend: 'savedStates',
config: {
update: false,
creationModal: true,
paging: true,
ajax: function (data, callback) {
console.log("[StateRestore] Incoming data:", data);
alert(data)
if (!data || !data.action) {
console.error("[StateRestore] No valid action in data");
return;
}
// RENAME
if (data.action === 'rename') {
let oldName = Object.keys(data.stateRestore)[0];
let newName = data.stateRestore[oldName];
let postData = {
userName: 'someUser',
query_id: 59,
name: oldName,
newName: newName
};
jQuery.ajax({
url: "data/php/rename_state.php",
type: "POST",
data: postData,
success: function (response) {
console.log("[Saved States] Rename Response:", response);
callback();
},
error: function (xhr, status, error) {
console.error("[Saved States] Rename Error:", error);
}
});
}
// REMOVE
else if (data.action === 'remove') {
let stateName = Object.keys(data.stateRestore)[0];
let postData = {
userName: 'someUser',
query_id: 59,
name: stateName
};
jQuery.ajax({
url: "data/php/d_state.php",
type: "POST",
data: postData,
success: function (response) {
console.log("[Saved States] Remove Response:", response);
callback();
},
error: function (xhr, status, error) {
console.error("[Remove State] AJAX Error:", error);
}
});
}
// LOAD
else if (data.action === 'load') {
let postData = {
userName: 'someUser',
query_id: 59
};
jQuery.ajax({
url: "data/php/load_states.php",
type: "POST",
data: postData,
dataType: "json",
success: function (response) {
let statesObj = {};
jQuery.each(response.states, function (_, state) {
statesObj[state.name] = JSON.parse(state.data);
});
console.log(statesObj)
callback(statesObj);
},
error: function (xhr, status, error) {
console.error("[Saved States] Load Error:", error);
}
});
}
// UPDATE
else if (data.action === 'update') {
let stateName = Object.keys(data.stateRestore)[0];
let stateData = data.stateRestore[stateName];
let postData = {
userName: 'someUser',
query_id: 59,
name: stateName,
state: stateData
};
jQuery.ajax({
url: "data/php/override_state.php",
type: "POST",
data: postData,
success: function (response) {
console.log("[Saved States] Update Response:", response);
callback();
},
error: function (xhr, status, error) {
console.error("[Saved States] Update Error:", error);
}
});
}
type: "POST"
}
},
Thank you!
With best regards,
Krystian
Answers
Hi Krystian,
The update button seems to execute the Ajax option correctly in this example.
Can you link to a test case showing the issue please?
Thanks,
Allan