How to delete row in jqgrid

in my jqgrid i have an icon and when i click on it i need to call ajax 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 function 2:

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 calling deleteNote () correctly? or am I doing something wrong? because nothing happens.

thank

+3


source to share


1 answer


If you want to have a delete button for each line, you can add it via

    {name : 'actions', index: 'actions', formatter:'actions',
    formatoptions: {
    keys: true,
    editbutton: false,
    delOptions: { url: '/controller/deleteRecordAction' }
    }},

      



You must specify your own controller action instead of the above url to handle the delete action.

Here is a working example http://jsfiddle.net/dumbguy5689/9ueDL/6/

+4


source







All Articles