Reputation: 177
in my jqgrid i have an icon and when i click on it I have to call a ajax's function to delete data in my db.
this is the code:
function loadnotespese(){
$("#clienti-navgrid").jqGrid( {
....
colNames:['Tipo spesa','Importo','Unita di misura','Descrizione',''],
colModel:[
{name:'category', index:'category', width:'20', sortable:false},
{name:'value', index:'value', width:'10', sortable:false},
{name:'um', index:'um', width:'5', sortable:false},
{name:'note', index:'note', width:'30', sortable:false},
{name:'links', index:'links', width:'5', sortable:false, align:'center', formatter: currencyFmatter,
cellattr: function (rowId, tv, rawObject, cm, rdata) {
return ' onClick="deleteNote(' + rowId + ')"';
}
},
],
....
});//jqGrid
}
here the 2 function:
function currencyFmatter(cellvalue, options, rowObject) {
var cellValue = rowObject.id;
return "<img title= 'Elimina' src='/images/delete-icon.png' />";
}
function deleteNote(value){
var params = {};
params['idProgetto'] = value;
$.ajax({
url: '/project/deletenota.do',
type: 'GET',
dataType: 'json',
data: params,
success: function(response){
if (response != "error"){
$("#clienti-navgrid").trigger("reloadGrid", [{current: true}]);
dialogNotice("Nota spesa inserita<br/> ", 300, 150);
}
else
dialogNotice("E' avvenuto un errore nell'inserimento della nota spesa<br/> ", 300, 150);
}
});
}
is it correct call deleteNote() like this? or i wrong something? because nothing happens.
Thanks
Upvotes: 3
Views: 14925
Reputation: 3123
If you want to have a delete button per row you could add it via
{name : 'actions', index: 'actions', formatter:'actions',
formatoptions: {
keys: true,
editbutton: false,
delOptions: { url: '/controller/deleteRecordAction' }
}},
You would specify your own controller action in place of the above url to handle the delete action.
Here is a working example http://jsfiddle.net/dumbguy5689/9ueDL/6/
Upvotes: 4