2

当页面上同时有多个 jqGrid 时,它们的子元素 ID 可能会发生冲突。您可能希望将三个或四个相同的网格一个一个叠放在另一个之上,显示相同的数据,但来自不同的年份。

子元素 id 应该在它们前面加上 table-id。是否有执行此操作的“完全限定|详细 ID”设置?

谢谢

4

1 回答 1

0

First of all I find your question very interesting, so +1 for the question. What you find out can be really large problem which can be difficult diagnosed. So I recommend you to place the corresponding suggestion in the feature request on http://www.trirand.com/blog/?page_id=393/feature-request/.

Now about the workaround possibilities. The easiest way is to generate an unique Ids for different grids on the server side. But it is of cause not always possible. You can add an id_prefix as an additional parameter of your server code which produce JSON/XML reply from jqGrid. Then server should add this prefix to all ids before sending back to jqGrid. This workaround is not nice but it will work.

Another way which I see is the changing of id of all jqGrids rows with respect of jsonReader (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function). If you add to the jqGrid the parameter like following:

jsonReader: { id: function(obj) { return "BlaBla" + obj.id; } }

then all ids in the table will receive prefix "BlaBla". If you use jqGrids on your page only to display data in the grid this can be your solution. You should don't forget about possible new problems which produce this workaround. If you use master/detail scenario, Edit/Delete etc you have to take in consideration, that ids of grids will have prefixes now. So you will have to include additional code in evens like onclickSubmit, serializeRowData, serializeGridData and so on to cut the prefix before the usage of id or before sending ids to the server.

于 2010-06-25T22:56:05.603 回答