Jquery Bootgrid,单击时行为空
我已经创建了一个通用函数,所以我可以在不同的页面上使用相同的代码 我使用Ajax加载数据,当下拉列表的值更改时,我刷新我的表。单击行时,该值为空: 这是我的dataTable函数Jquery Bootgrid,单击时行为空,jquery,jquery-bootgrid,Jquery,Jquery Bootgrid,我已经创建了一个通用函数,所以我可以在不同的页面上使用相同的代码 我使用Ajax加载数据,当下拉列表的值更改时,我刷新我的表。单击行时,该值为空: 这是我的dataTable函数 function dataTable() { var self = this; self.url = ""; self.gridObject = null; self.Initilize = function (tableDiv, url) { self.url
function dataTable() {
var self = this;
self.url = "";
self.gridObject = null;
self.Initilize = function (tableDiv, url) {
self.url = url;
self.gridObject = $("#" + tableDiv).bootgrid({
formatters: {
"commands": function (column, row) {
return "<button type=\"button\" class=\"btn btn-sm btn-success command-edit\" data-row-id=\"" + row.Id + "\"><span class=\"fa fa-pencil\"></span></button> " +
"<button type=\"button\" class=\"btn btn-sm btn-danger command-delete\" data-row-id=\"" + row.Id + "\"><span class=\"fa fa-trash-o\"></span></button>";
}
},
requestHandler: function (request) {
var model = fleetMaintenance.filterModel.GetModel();
model.Current = request.current;
model.RowCount = request.rowCount;
model.Search = request.searchPhrase;
return JSON.stringify(model);
},
ajaxSettings: {
method: "POST",
contentType: "application/json"
},
ajax: true,
url: self.url,
selection: true,
}).on("loaded.rs.jquery.bootgrid", function () {
self.gridObject.find(".command-edit").on("click", function (e) {
// e.stopPropagation();
alert("You pressed edit on row: " + $(this).data("row-id"));
}).end().find(".command-delete").on("click", function (e) {
// e.stopPropagation();
alert("You pressed delete on row: " + $(this).data("row-id"));
});
self.gridObject.on("click.rs.jquery.bootgrid", function (e, columns, row) {
console.log(row);
debugger;
});
});
},
self.RefreshTable = function () {
self.gridObject.bootgrid('reload');
}
}
函数数据表(){
var self=这个;
self.url=“”;
self.gridObject=null;
self.Initilize=function(tableDiv,url){
self.url=url;
self.gridObject=$(“#”+tableDiv).bootgrid({
格式化程序:{
“命令”:功能(列、行){
返回“”+
"";
}
},
requestHandler:函数(请求){
var model=fleetMaintenance.filterModel.GetModel();
model.Current=request.Current;
model.RowCount=request.RowCount;
model.Search=request.searchPhrase;
返回JSON.stringify(model);
},
Ajax设置:{
方法:“张贴”,
contentType:“应用程序/json”
},
阿贾克斯:没错,
url:self.url,
选择:正确,
}).on(“loaded.rs.jquery.bootgrid”,函数(){
self.gridObject.find(“.command edit”).on(“单击”,函数(e){
//e.停止传播();
警报(“您按了行上的编辑:”+$(this).data(“行id”);
}).end().find(“.command delete”)。在(“单击”上,函数(e){
//e.停止传播();
警报(“您在行上按了删除:”+$(this).data(“行id”);
});
self.gridObject.on(“click.rs.jquery.bootgrid”),函数(e,列,行){
控制台日志(行);
调试器;
});
});
},
self.refreshttable=函数(){
self.gridObject.bootgrid('reload');
}
}
HTML:
地点
身份证件
站点名称
命令
然后我用它来创建JQGrid表:
<script type="text/javascript">
var tble = new dataTable();
$(function () {
tble.Initialize('sitesList', '/Sites/SitesList')
$('*[data-action="RefreshTable"]').change(function (e) {
var dropDown = $(this);
tble.RefreshTable();
});
});
</script>
var tble=新数据表();
$(函数(){
tble.Initialize('sitesList','/Sites/sitesList'))
$('*[data action=“RefreshtTable”]')。更改(函数(e){
var下拉列表=$(此);
tble.refreshttable();
});
});
当用户单击此表中的一行时,我必须重新加载另一个表:但行为NULL
注意:当我没有使用Ajax加载数据时,这并没有发生:
以防其他人有此问题: 似乎我们必须在Id列上设置
data type=“numeric”
,如果我删除此数据属性,则单击时的行为空:
<table id="sitesList" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="iSiteId" data-identifier="true" data-type="numeric">Id</th>
<th data-column-id="sSiteName" data-order="desc">Site Name</th>
<th data-column-id="sNotes">Notes</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
<tbody></tbody>
</table>
身份证件
站点名称
笔记
命令
<table id="sitesList" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="iSiteId" data-identifier="true" data-type="numeric">Id</th>
<th data-column-id="sSiteName" data-order="desc">Site Name</th>
<th data-column-id="sNotes">Notes</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
<tbody></tbody>
</table>