【问题标题】:Can't get IDs after reloading jqGrid on specific page在特定页面上重新加载 jqGrid 后无法获取 ID
【发布时间】:2013-12-27 21:08:31
【问题描述】:

我在 MVC 应用程序中使用 jqGrid。我正在使用"scroll: true" 选项。我的问题是;在特定页面上重新加载 jqGrid 后:

$("#jqTable").trigger("reloadGrid", [{ page: next_page }]);

我无法获得应该存在的新 ID:

var ids = $("#jqTable").getDataIDs();

编辑

另外,我忘了说 reloadGrid 后我什至看不到下一页的行。

这里有更详细的解释:

有一个网页,我必须在 jquery 对话框中的 Enter 键上显示 jqgrid 中某些选定行的详细信息。我只用 Enter 键逐行遍历网格。首先输入 = 打开对话框。第二个输入是保存。因此,我必须根据客户的意愿标记当前行并选择下一行的代码是:

//declaration of global variables as selected_index -> current index of id in $("#jqTable").getDataIDs() array ...
//...

//In this moment jquery dialog is open. I work on jqgrid on underlying page:

//Set status of current row:
$("#" + selected_row_id).find("td").css("background-color", "azure");
$("#jqTable").jqGrid("setCell", selected_row_id, "Status", "Completed");

//Select next row:
selected_index = selected_index + 1;
temp_id = selected_row_id;
selected_row_id = $("#jqTable").getDataIDs()[selected_index];
if (selected_row_id === undefined) {
    //If I am here it means that I have to jump to next page!
    //Trying to simulate virtual scroll if id is undefined - because id is on the next page!
    current_page = current_page + 1; // SO, IT IS NEXT PAGE!
    $("#jqTable").trigger("reloadGrid", [{ page: current_page }]);

    //Here selected_row_id is still undefined after this line of code:
    selected_row_id = $("#jqTable").getDataIDs()[selected_index];
}
$("#jqTable").setSelection(selected_row_id, true);

【问题讨论】:

  • 请提供更多代码和标记,至少发布您获得 ID 的代码/事件块
  • 我会的。我是网站上的新手,所以我必须等待 8 小时才能收到新帖子...
  • 您应该编辑现有问题,而不是创建新问题。
  • 感谢马克西姆的小费!
  • 请帮忙!我还没有解决方案。

标签: jquery asp.net-mvc jqgrid scroll


【解决方案1】:

$("#jqTable").trigger("reloadGrid")loadComplete 内部的事件处理程序集选择相对于$("#jqTable").setSelection(rowid)。 尝试在loadComplete 事件处理程序中这样做,

loadComplete: function () {
       selected_row_id = $("#jqTable").getDataIDs()[selected_index];
}

假设您在重新加载后尝试获取低于 $("#jqTable") 的 id,试试这个,

 var IDs = [];
    $("#jqTable").find("span").each(function(){ IDs.push(this.id); }); // find with your element as span

jQuery 的内置 map() 函数:

var IDs = $("#jqTable span[id]")         // find spans with ID attribute
  .map(function() { return this.id; }) // convert to set of IDs
  .get(); // convert to instance of Array (optional)

【讨论】:

  • 感谢您的回答。使用此代码,我得到了空数组。但是,也许,我的问题是我试图在弹出窗口(jquery 对话框)打开时重新加载网格并获取 ID,所以可能只有在对话框关闭后才会重新加载 jqgrid。有可能吗?
  • 请帮忙!我还没有解决方案。
  • Vedran,您是否要获取所选行下的 ID?
  • 不,我正在尝试在下一页重新加载网格,并从此页面获取 ID。
  • 我现在看到,如果我强制第 2 页,例如: $("#jqTable").trigger("reloadGrid", [{ page: 2 }]);我的 jqGrid 仍会将 page=1 参数传递给控制器​​的方法。这就是为什么这段代码没有帮助的原因。
【解决方案2】:

这一行:

$("#jqTable").closest(".ui-jqgrid-bdiv").scrollTop(2400);

帮助我以编程方式滚动,等待刷新网格数据的超时帮助我选择合适的行!

但是,这不是稳定的解决方案。我必须检查一下...

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多