Bootstrap table 不会排序
Bootstrap table won't sort
我正在创建一个 bootstrap 4 table 像这样:
dataElement = $('<table id="' + questionID + 'table" data-toggle="table">');
dataElement.bootstrapTable({
url: "api/eval/getAnswersToQuestion.php",
method: "post",
contentType: "application/x-www-form-urlencoded",
queryParams: function(params){
params["questionID"] = questionID;
return params;
},
sortable: true,
sortName: questionID,
columns: [
{
field: 'token',
title: 'Answer token'
},
{
field: questionID,
title: 'Answer',
sortable: true
}
]
});
默认将第二列降序排列。但是,无法单击 table header 来更改排序顺序。我错过了什么?在对应的example中是这样操作的
table 尚未添加到 DOM。您正在代码段的第一行创建一个新的 table
节点,并在下一行调用该节点上的 bootstrapTable
。很好,节点将正确显示,但不会交互(例如排序不起作用)。
为了使bootstrap table 正常工作,请确保调用bootstrapTable
方法时该节点已经存在于DOM 中。这是因为bootstraptable要将table节点转化为bootstraptable结构,在DOM之外不起作用。
我正在创建一个 bootstrap 4 table 像这样:
dataElement = $('<table id="' + questionID + 'table" data-toggle="table">');
dataElement.bootstrapTable({
url: "api/eval/getAnswersToQuestion.php",
method: "post",
contentType: "application/x-www-form-urlencoded",
queryParams: function(params){
params["questionID"] = questionID;
return params;
},
sortable: true,
sortName: questionID,
columns: [
{
field: 'token',
title: 'Answer token'
},
{
field: questionID,
title: 'Answer',
sortable: true
}
]
});
默认将第二列降序排列。但是,无法单击 table header 来更改排序顺序。我错过了什么?在对应的example中是这样操作的
table 尚未添加到 DOM。您正在代码段的第一行创建一个新的 table
节点,并在下一行调用该节点上的 bootstrapTable
。很好,节点将正确显示,但不会交互(例如排序不起作用)。
为了使bootstrap table 正常工作,请确保调用bootstrapTable
方法时该节点已经存在于DOM 中。这是因为bootstraptable要将table节点转化为bootstraptable结构,在DOM之外不起作用。