jqgrid 通过单独的按钮将网格显示为子网格
我在使用额外按钮将网格显示为子网格时遇到问题。 我尝试从事件中复制代码
subGridRowExpanded:
。 但在 subGridRowExpanded 被触发之前,网格正在做一些令人讨厌的事情。 如果我使用左侧的 + 按钮,网格将正确显示。如果我现在按下创建的按钮,子网格也会重新加载。我在开始时使用警报来停止该函数,并且我看到该表被插入到 subGridRowExpanded 之前。
所以我想我在活动之前错过了一个功能。也许我在执行任务时使用了错误的事件。
这是我的代码,来自基本示例。生成按钮的函数:
gridComplete: function(){
var ids = jQuery("#task").jqGrid('getDataIDs');
var running_task_ids=get_running_task_id_ajax();
for(var i=0;i < ids.length;i++){
var cl = ids[i];
start = "<input style='height:22px;width:50px;' type='button' value='Start' onclick=\"start_stop_task('"+cl+"','start');\" />";
stop = "<input style='height:22px;width:50px;' type='button' value='Stop' onclick=\"start_stop_task('"+cl+"','stop');\" />";
se = "<input style='height:22px;width:50px;' type='button' value='Save' onclick=\"jQuery('#task').saveRow('"+cl+"');\" />";
//ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#task').restoreRow('"+cl+"');\" />";
co = "<input style='height:22px;width:70px;' type='button' value='Comment' onclick=\"foobar('task_"+cl+"',"+cl+");\" />";
}
}
被调用的函数(刚刚从网格复制为子网格示例):
function foobar(subgrid_id, row_id) {
// klappt noch nicht!
alert(subgrid_id+":"+row_id);
// we pass two parameters
// subgrid_id is a id of the div tag created whitin a table data
// the id of this elemenet is a combination of the "sg_" + id of the row
// the row_id is the id of the row
// If we wan to pass additinal parameters to the url we can use
// a method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the flowing
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id+"_t";
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
url:"ajax/listtasktime/id/"+row_id,
onSelectRow:
function(id){
if(id && id!==lastsel2){
jQuery('#'+subgrid_table_id).jqGrid('restoreRow',lastsel2);
//jQuery('#task').jqGrid('editRow',id,true,pickdates_e);
jQuery('#'+subgrid_table_id).jqGrid('editRow',id,true);
lastsel2=id; }
},
datatype: "xml",
colNames: ['ID','START','END', 'Time'],
colModel: [
{name:"ID",index:"num",width:80,key:true},
{name:"START",index:"item",width:180,editable: true},
{name:"END",index:"qty",width:180,align:"right",editable: true},
{name:"TIME",index:"qty",width:180,align:"right"}
],
rowNum:20,
pager: pager_id,
sortname: 'num',
sortorder: "asc",
height: '100%'
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false})
alert("done");
}
I have a Problem to Display a Grid as a Subgrid using an extra button.
I tried to copy the code from the
subGridRowExpanded:
Event.
But the Grid is doing something nasty, before the subGridRowExpanded is fired.
If I use the + button at the left side the grid is displayed properly. If I now push my created button, the subGrid is reloaded too. I used an alert to stop the function at the beginning and I saw the table is inserted before the subGridRowExpanded.
So I guess I'm missing a function before the Event. Maybe I'm using a wrong Event for my task.
Here is my Code which is from the Basic Example. The function which generates the Button:
gridComplete: function(){
var ids = jQuery("#task").jqGrid('getDataIDs');
var running_task_ids=get_running_task_id_ajax();
for(var i=0;i < ids.length;i++){
var cl = ids[i];
start = "<input style='height:22px;width:50px;' type='button' value='Start' onclick=\"start_stop_task('"+cl+"','start');\" />";
stop = "<input style='height:22px;width:50px;' type='button' value='Stop' onclick=\"start_stop_task('"+cl+"','stop');\" />";
se = "<input style='height:22px;width:50px;' type='button' value='Save' onclick=\"jQuery('#task').saveRow('"+cl+"');\" />";
//ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#task').restoreRow('"+cl+"');\" />";
co = "<input style='height:22px;width:70px;' type='button' value='Comment' onclick=\"foobar('task_"+cl+"',"+cl+");\" />";
}
}
The function which is called (just copied from the Grid as subgrid Example):
function foobar(subgrid_id, row_id) {
// klappt noch nicht!
alert(subgrid_id+":"+row_id);
// we pass two parameters
// subgrid_id is a id of the div tag created whitin a table data
// the id of this elemenet is a combination of the "sg_" + id of the row
// the row_id is the id of the row
// If we wan to pass additinal parameters to the url we can use
// a method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the flowing
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id+"_t";
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
url:"ajax/listtasktime/id/"+row_id,
onSelectRow:
function(id){
if(id && id!==lastsel2){
jQuery('#'+subgrid_table_id).jqGrid('restoreRow',lastsel2);
//jQuery('#task').jqGrid('editRow',id,true,pickdates_e);
jQuery('#'+subgrid_table_id).jqGrid('editRow',id,true);
lastsel2=id; }
},
datatype: "xml",
colNames: ['ID','START','END', 'Time'],
colModel: [
{name:"ID",index:"num",width:80,key:true},
{name:"START",index:"item",width:180,editable: true},
{name:"END",index:"qty",width:180,align:"right",editable: true},
{name:"TIME",index:"qty",width:180,align:"right"}
],
rowNum:20,
pager: pager_id,
sortname: 'num',
sortorder: "asc",
height: '100%'
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false})
alert("done");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到的。您不必调用单独的函数。从 jqGrid 3.3 或类似版本开始,有一个函数称为:
或者
您可以像这样调用该函数:
中的注册函数。
如果单击,则调用事件
I found it myself. You don´t have to call a seperate function. Since jqGrid 3.3 or something like that, there is a function called:
or
you can call the function like this:
If clicked the registered function from the
Event is called.