gpt4 book ai didi

jQuery Bootgrid 无法正常工作

转载 作者:行者123 更新时间:2023-12-01 00:22:20 24 4
gpt4 key购买 nike

我需要一些帮助。我在使用 ajax 的页面上有一个 jQuery Bootgrid。当数据正确加载并且网格正确呈现时。所有功能似乎都无法正常工作,包括搜索框、排序、刷新等。同样,我也没有收到任何 JavaScript 错误。

我引用的是以下内容

  • jquery.bootgrid.min.css
  • jquery.bootgrid.min.js
  • jquery.bootgrid.fa.min.js

我的代码非常基础

HTML

<table id="jobGrid" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="JobNumber" data-identifier="true" data-type="string">Job Number</th>
<th data-column-id="JobName" data-type="string">Job Name</th>
<th data-column-id="JobState" data-type="string">Request State</th>
<th data-column-id="JobStatus" data-type="string">Status</th>
<th data-column-id="JobRequestor" data-type="string">Requestor</th>
<th data-column-id="LastModifiedDate" data-type="date" data-order="desc">Last Modified</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
</table>

JavaScript

// Planning Filter
var planningFilter = function () {
// NOTE: I have multiple types of basic filters.
// eg: Planning, Approved, Completed
$("#jobGrid").bootgrid("destroy");
var grid = $("#jobGrid").bootgrid({
ajax: true,
ajaxSettings: {
method: "GET",
cache: false
},
url: RestService.GetJobsInPlanningSvr(),
formatters: {
"commands": function (column, row) {
return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.JobNumber + "\"><span class=\"fa fa-pencil\"></span>&nbsp;&nbsp;View Details</button>";
}
}
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
grid.find(".command-edit").on("click", function (e) {
alert("You pressed edit on row: " + $(this).data("row-id"));
});
});
}

JSON 结果

{
"current":1,
"rowCount":10,
"rows":[
{"CustomerID":"88888888-8888-8888-8888-888888888888","JobNumber":"DMPC-2","JobName":"DMPC-2: Transfer 645 Units to Warehouse","JobState":"Request Draft","JobStatus":"In Planning","JobRequestor":"Jim Halpert","LastModifiedUTS":1439768413,"LastModifiedDate":"8/16/2015"},
{"CustomerID":"88888888-8888-8888-8888-888888888888","JobNumber":"DMPC-1","JobName":"DMPC-1: Scranton Chamber of Commerce Delivery","JobState":"Request Draft","JobStatus":"Pending Approval","JobRequestor":"Dwight Schrute","LastModifiedUTS":1440009361,"LastModifiedDate":"8/19/2015"}
],
"total":2
}

基本上就是这样...您可以看到为什么所有功能都不起作用的任何原因...不是:我还没有测试分页,但如果这不起作用,我也不会感到惊讶。

感谢您的帮助

最佳答案

问题是,该函数是在页面元素完全加载之前执行的。

您可以将函数放入$(function() { });

例如

$(function() {  
// Planning Filter
var planningFilter = function () {
// NOTE: I have multiple types of basic filters.
// eg: Planning, Approved, Completed
$("#jobGrid").bootgrid("destroy");
var grid = $("#jobGrid").bootgrid({
ajax: true,
ajaxSettings: {
method: "GET",
cache: false
},
url: "data.json",
formatters: {
"commands": function (column, row) {
return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.JobNumber + "\"><span class=\"fa fa-pencil\"></span>&nbsp;&nbsp;View Details</button>";
}
}
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
grid.find(".command-edit").on("click", function (e) {
alert("You pressed edit on row: " + $(this).data("row-id"));
});
});
}

planningFilter();
});

Preview

关于jQuery Bootgrid 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32104242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com