gpt4 book ai didi

jqgrid - 如何在jqgrid中删除带有本地数据的行

转载 作者:行者123 更新时间:2023-12-04 11:14:18 25 4
gpt4 key购买 nike

jqGrid 参数 loadonce: true 使用

选择行并按删除按钮

未设置网址

如何仅删除本地数据中的行并抑制此错误消息?
是否可以设置一些虚拟 url 或任何其他想法来允许行删除?
如果添加和编辑表单也可以用于本地数据,那就太好了。

            url: 'GetData',
datatype: "json",
multiselect: true,
multiboxonly: true,
scrollingRows : true,
autoencode: true,
loadonce: true,
prmNames: {id:"_rowid", oper: "_oper" },
rowTotal: 999999999,
rownumbers: true,
rowNum: 999999999,

更新 1

从 Oleg 的回答中,我理解了以下解决方案:
  • 禁用 jqGrid 标准删除按钮
  • 向工具栏添加新的删除按钮。
  • 从此按钮单击事件调用提供

    grid.jqGrid('delGridRow', rowid, myDelOptions);

  • 方法。
    可以选择多行。如何删除所有选定的行,此示例仅删除一个?

    更改 jqGrid 以便删除、编辑、添加按钮在没有 url 的情况下工作不是更好吗?目前需要传递虚拟 url,它总是为本地数据编辑返回成功。

    最佳答案

    您可以使用 delRowData方法删除任何本地行。

    您可以使用 delGridRow如果需要,可以从表单编辑中获取。我描述的方式here并用于格式化程序:'actions'(参见 herehere 和最初的 here )。

    var grid = $("#list"),
    myDelOptions = {
    // because I use "local" data I don't want to send the changes
    // to the server so I use "processing:true" setting and delete
    // the row manually in onclickSubmit
    onclickSubmit: function(options, rowid) {
    var grid_id = $.jgrid.jqID(grid[0].id),
    grid_p = grid[0].p,
    newPage = grid_p.page;

    // reset the value of processing option which could be modified
    options.processing = true;

    // delete the row
    grid.delRowData(rowid);
    $.jgrid.hideModal("#delmod"+grid_id,
    {gb:"#gbox_"+grid_id,
    jqm:options.jqModal,onClose:options.onClose});

    if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
    if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
    // if after deliting there are no rows on the current page
    // which is the last page of the grid
    newPage--; // go to the previous page
    }
    // reload grid to make the row from the next page visable.
    grid.trigger("reloadGrid", [{page:newPage}]);
    }

    return true;
    },
    processing:true
    };

    然后使用
    grid.jqGrid('delGridRow', rowid, myDelOptions);

    更新 : 如果是 multiselect: true myDelOptions可以修改为以下内容:
    var grid = $("#list"),
    myDelOptions = {
    // because I use "local" data I don't want to send the changes
    // to the server so I use "processing:true" setting and delete
    // the row manually in onclickSubmit
    onclickSubmit: function(options) {
    var grid_id = $.jgrid.jqID(grid[0].id),
    grid_p = grid[0].p,
    newPage = grid_p.page,
    rowids = grid_p.multiselect? grid_p.selarrrow: [grid_p.selrow];

    // reset the value of processing option which could be modified
    options.processing = true;

    // delete the row
    $.each(rowids,function(){
    grid.delRowData(this);
    });
    $.jgrid.hideModal("#delmod"+grid_id,
    {gb:"#gbox_"+grid_id,
    jqm:options.jqModal,onClose:options.onClose});

    if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
    if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
    // if after deliting there are no rows on the current page
    // which is the last page of the grid
    newPage--; // go to the previous page
    }
    // reload grid to make the row from the next page visable.
    grid.trigger("reloadGrid", [{page:newPage}]);
    }

    return true;
    },
    processing:true
    };

    更新 2 : 要在删除操作上使用键盘支持并将“删除”按钮设置为默认值,您可以在 delSettings 中添加附加选项
    afterShowForm: function($form) {
    var form = $form.parent()[0];
    // Delete button: "#dData", Cancel button: "#eData"
    $("#dData",form).attr("tabindex","1000");
    $("#eData",form).attr("tabindex","1001");
    setTimeout(function() {
    $("#dData",form).focus(); // set the focus on "Delete" button
    },50);
    }

    关于jqgrid - 如何在jqgrid中删除带有本地数据的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6796480/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com