使用 GET 从 jqGrid 中的列值链接到新页面
我创建了一个 jqGrid,其中包含一些字段,例如:
job_id、name 等
我想要做的是,当单击 job_id 列中的值时,它会将它们重定向到:
job.php?job_id= (他们点击的值)
我首先尝试使用以下内容作为我的 colModel:
{ name:'job_id', index:'job_id', edittype:'select', formatter:'showlink',
formatoptions:{baseLinkUrl:'job.php'}, width:50, align:'center' }
但这会导致重定向到:
job.php?job_id=(row_id)
我做了一些搜索,发现了开发人员的帖子该软件的开源版本建议使用以下 colModel 和附加 JS:
{ name:'job_id', index:'job_id', edittype:'select', formatter:'showlink',
formatoptions:{baseLinkUrl:'#'}, width:50, align:'center' }
loadComplete: function() {
var myGrid = $("#home_list");
var ids = myGrid.getDataIDs();
for (var i = 0, idCount = ids.length; i < idCount; i++) {
$("#"+ids[i]+" a",myGrid[0]).click(function(e) {
var hash=e.currentTarget.hash;// string like "#?id=0"
if (hash.substring(0,5) === '#?id=') {
var id = hash.substring(5,hash.length);
var text = this.textContent;
location.href="job.php?id="+text;
}
e.preventDefault();
});
}
}
但这与 IE 不兼容。除此之外,当在 jqGrid 中显示大量行时,加载需要非常长的时间,例如 500 行需要 5 秒+。
我会继续努力,但这有其他人做过吗?
I have created a jqGrid that contains some fields such as:
job_id, name, etc
What I am trying to do is make so that when the click on the value in the job_id column, it will redirect them to:
job.php?job_id=(value that they clicked on)
I started by trying to use the following as my colModel:
{ name:'job_id', index:'job_id', edittype:'select', formatter:'showlink',
formatoptions:{baseLinkUrl:'job.php'}, width:50, align:'center' }
But what this results in is a redirection to:
job.php?job_id=(row_id)
I did some searching, and found a post by the developer of the open source version of this software who suggested using the following colModel and additional JS:
{ name:'job_id', index:'job_id', edittype:'select', formatter:'showlink',
formatoptions:{baseLinkUrl:'#'}, width:50, align:'center' }
loadComplete: function() {
var myGrid = $("#home_list");
var ids = myGrid.getDataIDs();
for (var i = 0, idCount = ids.length; i < idCount; i++) {
$("#"+ids[i]+" a",myGrid[0]).click(function(e) {
var hash=e.currentTarget.hash;// string like "#?id=0"
if (hash.substring(0,5) === '#?id=') {
var id = hash.substring(5,hash.length);
var text = this.textContent;
location.href="job.php?id="+text;
}
e.preventDefault();
});
}
}
But this is not compatible with IE. In addition to this, when displaying a large number of rows in the jqGrid, it takes a extremely long time to load, say 5 seconds + for 500 rows.
I'm going to keep working on this, but is this something that anyone else has done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了我的旧答案中的代码示例,所以我决定应该回答您的问题。
我同意批评家关于
loadComplete
代码性能的观点。所以我对你的问题+1。长循环内部的构造$("#"+ids[i]+" a", myGrid[0])
运行速度可能非常慢。如果使用以下内容,可以轻松解决问题您可以看到 该演示与原始演示完全相同。为了展示该方法在 1000 行上的性能,我创建了另一个演示。可以看出,新方法见效很快。
现在回到你的主要问题。如果您编写自定义格式化程序,我们将获得最佳性能和 unformatter 而不是使用预定义的格式化程序显示链接。代码可以如下所示:
确切的代码取决于您使用的
datatype
、是否使用loadonce:true
以及您使用的jsonReader
使用。例如,在您的情况下,rowObject
是数组,您必须使用相应数据字段的数组索引(如
rowObject[4]
)而不是rowObject.job_id
。更新:我认为最好的实现方式是使用 onCellSelect 或 beforeSelectRow,而不是将单击事件绑定到列中的每个元素。我建议阅读以下答案以了解详细信息:这个,另一个和另一个旧答案。
You used code example from my old answer so I decide I should answer on you question.
I agree with the critic about performance of the code of the
loadComplete
. So +1 from me for your question. The construct$("#"+ids[i]+" a", myGrid[0])
inside of long loop can work very slowly. One can easy fix the problem if one will use the followingYou can see that the improved version of the demo works exactly as the original demo. To show the performance of the method on 1000 rows I created one more demo. One can see that the new method works quickly.
Now back to your main problem. The best performance we will receive if you write your custom formatter and unformatter instead of the usage of the predefined formatter showlink. The code can be about following:
The exact code depend on which
datatype
you use, whether you useloadonce:true
or not and whichjsonReader
you use. It can be for example, thatrowObject
is array in your case and you have to usearray index of the corresponding data field (like
rowObject[4]
) instead ofrowObject.job_id
.UPDATED: I think the best implementation way will be the usage of onCellSelect or beforeSelectRow instead of binding click event to every element in the column. I recommend to read the following answers for details: this one, another one and one more old answer.