jqGrid :当页面上出现多个网格时,子元素 id 可能会发生冲突:是否有一种设置可以避免这种情况?
当页面上同时有多个 jqGrid 时,它们的子元素 id 可能会发生冲突。您可能希望将三个或四个相同的网格堆叠在一起,显示相同的数据但来自不同的年份。
子元素 id 应该在其前面添加 table-id。是否有“完全限定|详细 ids”设置可以执行此操作?
谢谢
When you have more than one jqGrid on the page at the same time, their child-element ids can conflict. You might want to have three or four identical grids stacked one above the other, showing the same data but from different years.
Child-element ids should have the table-id prepended to them. Is there a "fully-qualified|verbose ids" setting that does this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我发现你的问题很有趣,所以这个问题+1。您发现的问题可能是非常大的问题,很难诊断。因此,我建议您将相应的建议放在 http: //www.trirand.com/blog/?page_id=393/feature-request/。
现在讨论解决方法的可能性。最简单的方法是在服务器端为不同的网格生成唯一的Id。但这并不总是可能的。您可以添加 id_prefix 作为服务器代码的附加参数,该参数会从 jqGrid 生成 JSON/XML 回复。然后服务器应该在发送回 jqGrid 之前将此前缀添加到所有 id 中。这个解决方法不太好,但它会起作用。
我看到的另一种方法是更改所有 jqGrids 行的 id 相对于 jsonReader 的内容(参见 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieve_data#jsonreader_as_function)。如果您向 jqGrid 添加如下参数:
那么表中的所有 id 都会收到前缀“BlaBla”。如果您在页面上使用 jqGrids 仅在网格中显示数据,这可能是您的解决方案。您不应该忘记可能产生此解决方法的新问题。如果您使用主/详细场景、编辑/删除等,则必须考虑网格的 id 现在将具有前缀。因此,您必须在事件中包含额外的代码,例如
onclickSubmit
、serializeRowData
、serializeGridData
等,以便在使用 id 或在将 ids 发送到服务器之前。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: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.