如何删除行并重新加载网格,同时将一个网格中的一行添加到另一个网格中 [英] How to delete row and reload the grid while adding a row from one grid to another

查看:103
本文介绍了如何删除行并重新加载网格,同时将一个网格中的一行添加到另一个网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jqgrid中使用了multiselect.我正在实现从第一个jqgrid向第二个jqgrid添加行,同时我从已选择的第一个网格中删除同一行

I am using multiselect in my jqgrid. I am implementing adding row from 1st jqgrid to 2nd jqgrid,at the same time I am removing same row from 1st grid which I have been selected

通过使用演示,我使用了永久多选概念.

By using the demo I make use of permanent multiselect concept.

通过使用这种概念,我甚至可以选择其他页面中的行,也可以复制它.

By using that concept I am able to select row even in other pages and I am able to copy it.

我的问题从这里开始:

我在第一网格中有6条记录,行号是5.因此,我将有两页,其中第一页有5行,第二页有第六行.

I have 6 records in 1st grid and my row number is 5. So I will have have two pages with 5 rows in 1 page and 6th row in 2nd page.

当我选择第1页的行和第2页的第6行并能够从第一个jqgrid移动到第二个jqgrid的数据时,同时我需要删除第一个jqgrid中的数据,就像我在第二个页面中删除时一样data,第6行将被删除,即使我使用了trigger("reloadGrid");

When I select the a row in page1 and 6th row in page2 and able to move to data from 1st jqgrid to 2nd jqgrid and at the same time I need to delete data in 1st jqgrid.As I was in 2nd page while deleting data,6th row will be deleted and its not showing the page 1 even though I have use the trigger("reloadGrid");

这是我用于从第一个jqgrid到第二个jqgrid添加和删除行的代码

Here is the code which I use for adding and deleting row from 1st jqgrid to 2nd jqgrid

var questionids = idsOfSelectedRows;
var questionLength = questionids.length;
for (var i=0; i < questionLength; i++) 
{
 var selectedId = questionids[i];
 var selectedData = $('#questions_list').jqGrid('getLocalRow', selectedId);
 $('#selectedQuestions_list').jqGrid('addRowData', selectedId, selectedData);
 $('#selectedQuestions_list').trigger("reloadGrid");
}

for (var i = 0; i < questionLength ; i++) { 
 var selectedId = questionids[i];
 console.log("delete is "+ $('#questions_list').jqGrid('delRowData', selectedId));
 //$('#questions_list').trigger("reloadGrid");
}

任何人都可以在代码中提供帮助,谢谢.

Please can anyone help in the code,Thanks in Advance.

推荐答案

在哪里获得idsOfSelectedRows?我想您使用getDataIDs来获取当前页面行的所有ID .如果将 local 网格或带有loadonce: true的网格使用,则内部参数data_index将由jqGrid填充.您可以使用for-in循环枚举_index的所有属性.通过这种方式,您将<网格>所有页面上所有行的ID .

Where you get idsOfSelectedRows? I suppose that you used getDataIDs to get all ids of rows of the current page. If you use local grid or grid with loadonce: true the internal parameters data and _index will be filled by jqGrid. You can use for-in loop to enumerate all properties of _index. In the way you will get ids of all rows over all pages of the grid.

此外,如果您添加行,则在添加每行后不应调用reloadGrid.它会多次降低性能.取而代之的是,您可以手动操作目标网格的_indexdata,然后调用一次reloadGrid.

Moreover, if you add multiple rows you should not call reloadGrid after adding of every row. It reduce performance in multiple times. Instead of that you can manipulate manually _index and data of destination grid and then call reloadGrid once.

接下来,我在答案中为您解释了上一个问题,即您应该编写代码以便产生代码没有ID重复.您当前的代码具有明确的ID重复项.源网格中存在ID为selectedId的行.如果使用.jqGrid('addRowData', selectedId, selectedData);,则具有相同ID selectedId 的行将添加到下一个网格中.因此,页面上将有两个具有相同ID的<tr>元素.如果使用.jqGrid('delRowData', selectedId)),则可以从另一个网格中删除行.通常,使用具有ID重复项的页面可能会产生不可预测的结果.不同的Web浏览器可以产生不同的结果.

More then that I explained you in the answer on your previous question that you should write the code so that it produce no id duplicates. You current code have definitively id duplicates. The row with id selectedId exist in the source grid. If you use .jqGrid('addRowData', selectedId, selectedData); the row with the same id selectedId will be added to the next grid. So you will have two <tr> element on the page with the same id. If you will use .jqGrid('delRowData', selectedId)) it could delete the rows from another grid. In general the working with the page having id duplicates can produce unpredictable results. Different web browsers can produce different results.

如果不确定是否存在id重复问题,则应在所有使用的网格中使用idPrefix选项和不同的值.

If you not sure whether you have or not have id dupplicate problem you should use idPrefix option with different values in all grids which you use.

这篇关于如何删除行并重新加载网格,同时将一个网格中的一行添加到另一个网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆