javascript - 无法从 jqgrid 中删除行

标签 javascript jquery jqgrid

情况:我正在开发一个 spring mvc webapp ,因为我试图为 jqgrid 中的每一行提供一个删除按钮,当用户单击删除按钮时,将执行一个 javascript 函数,该函数发送向 Controller 发出请求,该请求从服务器的数据库中删除该行,然后从 jqgrid 中删除该行,为了实现这一点,我的 html 如下:

<table id="grid"></table>
<div id="pager"></div>

JavaScript 如下:

var mydata = [{
    name: "Toronto",
    country: "Canada",
    continent: "North America"
}, {
    name: "New York City",
    country: "USA",
    continent: "North America"
}, {
    name: "Silicon Valley",
    country: "USA",
    continent: "North America"
}, {
    name: "Paris",
    country: "France",
    continent: "Europe"
}]

$("#grid").jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ["Name", "Country", "Continent","action"],
    colModel: [{
        name: 'name',
        index: 'name',
        editable: true,
    }, {
        name: 'country',
        index: 'country',
        editable: true,
    }, {
        name: 'continent',
        index: 'continent',
        editable: true,
    },{
        name: 'conti',
        index: 'cont',
        formatter : hello,
        editable: true, 

    }],
    pager: '#pager'
});

function hello(cellvalue, options, rowObject)
{
return '<a href="javascript:deleteRow(\'' + rowObject.name     
+'/');">delete</a>';
//code to remove this row from jqgrid
}

问题:现在,当按下删除按钮时,行将从服务器的数据库中删除,但我无法弄清楚如何从 jqgrid 中删除行,我尝试使用 delRowData但它需要 rowid 而我只有 rowobject ,谁能告诉我如何使用 rowobject 从 jqgrid 中删除相关行?

最佳答案

一般来说,建议包含 id输入数据中的属性。 id将用于分配值 id属性到网格的行( <tr> 元素)。

重要的是要知道options自定义格式化程序的参数包含可能对您有帮助的属性:options.rowIdoptions.colModel 。您可以转发options.rowId作为 deleteRow 的附加参数功能。

关于javascript - 无法从 jqgrid 中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37180000/

相关文章:

javascript - 在嵌入式应用程序中包含 JQuery 的最佳文件名

jquery - jqGrid colmodel 在 loadComplete 中的更改

jquery - jqgrid reloadGrid 将 loadonce 设置为 true

javascript - 幻灯片放映计时器

javascript - JQGrid for JQuery 只给出一个空白页

javascript - Javascript 对象中不平等的度量

javascript - "Http channel implementation doesn' t 支持 nsIUploadChannel2。一个扩展提供了一个非功能性的 http 协议(protocol)处理程序”

javascript - 聚焦后的 Mozilla 聚焦

javascript - 在 AJAX 调用的同时加载 HTML 片段

python - 如何在django中保存多个同名的html输入?