Closed pipiscrew closed 3 years ago
No it's not possible through the detailFormatter.
Use the onExpandRow
Event (like in the sub-table example), do you api request and render the table.
finally, I remove the data-toggle="table"
html5 attribute and initialize the bootstrap-table from JS as
$("#table<?= $entity ?>").bootstrapTable({
onExpandRow: function (index, row, $detail) {
$.ajax({
url : 'entities/<?= $entity ?>Helper.php',
dataType : 'json',
type : 'POST',
data : { 'action' : 'GetRecordDetails<?= $entity ?>JS', 'recID' : row.id },
success : function(data) {
var JSONFields = Object.keys(data[1]);
var columns = []
var rows = []
var row;
for (i = 0; i < JSONFields.length; i++) {
columns.push({
field: JSONFields[i],
title: JSONFields[i],
sortable: true
})
}
for (var i = 0; i < data.length; i++)
{
row = {};
for (j = 0; j < JSONFields.length; j++) {
row[JSONFields[j]] = data[i][JSONFields[j]];
}
rows.push(row);
}
//transform
$detail.bootstrapTable({
columns: columns,
data: rows
});
},
error : function(data) {
if (data)
alert(data.responseText);
}
});
}});
fantastic work...
Description
v1.18.3
[edit] hmm, sure is not possible with data-detail-formatter, no 'compatible' with AJAX (even with async property)....
any example with real time fetch and sub table?
Example (optional)
On bootstrap-table there are rows, and I would like, when user click the expand icon > Query the API > display the result data as child bootstrap date.
I'm using these properties on table HTML
the plus icon appear - fine
specifically, on the detailFormatter function can get the record ID - fine drawing a table, with the following code
the question how can I transform it to bootstrap-table ?
Using the method
.bootstrapTable()
is not possible there, needs an element.Or the only way to achieve this, is the Sub Table ref examples.bootstrap-table.com/index.html#welcomes/sub-table.html ?