3

在我的 jqgrid 中,我有一个图标,当我单击它时,我必须调用 ajax 的函数来删除我的数据库中的数据。

这是代码:

    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
}

这里有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);
            }
    });
}

像这样调用 deleteNote() 是否正确?还是我错了?因为什么也没有发生。

谢谢

4

1 回答 1

4

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/

于 2013-02-06T16:32:42.710 回答