Changing jtable action parameters (jquery) RUNTIME
I need to change the parameters of jtable actions AFTER initialization:
$('#tab-3').jtable({
title: 'Documenti Allegati',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'nomefile ASC',
actions: {
listAction: 'action.php?action=getAllegatiByID&id='+id,
deleteAction: 'action.php?action=delAllegatoByID&id='+id,
updateAction: 'action.php?action=updateAllegatiById&id='+id,
createAction:'temp'
},
fields:{
...
}
...
I need to change urA createAction. I tried searching in $ .hik.jtable.prototype.options but I couldn't find it.
Can anyone help me? many thanks
+3
source to share
1 answer
Operations
jtable accept either a url or a function i.e. from http://jtable.org/Demo/FunctionsAsActions .
createAction: function (postData) {
console.log("creating from custom function...");
return $.Deferred(function ($dfd) {
$.ajax({
url: '/Demo/CreateStudent',
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
},
error: function () {
$dfd.reject();
}
});
});
},
You can write your own function to return:
function myFunc(dfd){
return $.ajax({
url: myCustomUrlThatIwantToChangeDynamically,
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
},
error: function () {
$dfd.reject();
}
});
}
so the action can become:
createAction: function (postData) {
console.log("creating from custom function...");
return $.Deferred(myfunc($dfd););
},
and then you can change your url when you need and createAction will use the updated url.
Just a suggestion.
+2
source to share