Я пытаюсь выяснить, как изменить данные, отображаемые в дочерней строке таблицы, которую я использую Bootstrap -Table. Я искал документацию здесь https://examples.bootstrap-table.com/#welcome. html и не нашел никакой ценной информации, а также мне не повезло, прочитав прошлые сообщения здесь или в Google.
Таблица :
<table
id="table"
data-toolbar="#toolbar"
data-search="true"
data-show-refresh="true"
data-show-toggle="true"
data-show-fullscreen="true"
data-show-columns="true"
data-show-columns-toggle-all="true"
data-detail-view="true"
data-show-export="true"
data-click-to-select="true"
data-detail-formatter="detailFormatter"
data-minimum-count-columns="2"
data-show-pagination-switch="true"
data-pagination="true"
data-id-field="id"
data-page-list="[10, 25, 50, 100, all]"
data-side-pagination="server"
data-url="ajax.php"
data-response-handler="responseHandler" >
<thead>
<tr>
<tr>
<th data-field="id">ID</th>
<th data-field="name">Vendor</th>
<th data-field="company">Company</th>
<th data-field="type">Type</th>
<th data-field="status">Status</th>
<th data-field="owner">Owner</th>
</tr>
</tr>
</thead>
</table>
<script>
var $table = $('#table')
var $remove = $('#remove')
var selections = []
document.getElementById("Add").onclick = function () {
location.href = "new.php";
};
function getIdSelections() {
return $.map($table.bootstrapTable('getSelections'), function (row) {
return row.id
})
}
function responseHandler(res) {
$.each (res.rows, function (i, row) {
row.state = $.inArray(row.id, selections) !== -1
})
return res
}
function detailFormatter(index, row) {
var html = []
$.each(row, function (key, value) {
html.push('<p><b>' + key + ':</b> ' + value + '</p>')
})
return html.join('')
}
function operateFormatter(value, row, index) {
return [
'<a class="remove" href="javascript:void(0)" title="Remove">',
'<i class="fa fa-trash"></i>',
'</a>'
].join('')
}
window.operateEvents = {
'click .like': function (e, value, row, index) {
alert('You click like action, row: ' + JSON.stringify(row))
},
'click .remove': function (e, value, row, index) {
$table.bootstrapTable('remove', {
field: 'id',
values: [row.id]
})
}
}
function totalTextFormatter(data) {
return 'Total'
}
function totalNameFormatter(data) {
return data.length
}
function totalPriceFormatter(data) {
var field = this.field
return '$' + data.map(function (row) {
return +row[field].substring(1)
}).reduce(function (sum, i) {
return sum + i
}, 0)
}
function initTable() {
$table.bootstrapTable('destroy').bootstrapTable({
height: 700,
locale: $('#locale').val(),
columns: [
[{
field: 'state',
checkbox: true,
rowspan: 2,
align: 'center',
valign: 'middle'
}, {
title: '',
rowspan: 1,
align: 'center',
valign: 'middle',
sortable: true,
footerFormatter: totalTextFormatter
}, {
title: 'Vendor Details',
colspan: 5,
align: 'center'
}],
[{
field: 'name',
title: 'Vendor',
sortable: true,
footerFormatter: totalNameFormatter,
align: 'center',
}, {
field: 'company',
title: 'Company',
sortable: true,
align: 'center',
footerFormatter: totalPriceFormatter
},{
field: 'status',
title: 'Status',
sortable: true,
align: 'center',
footerFormatter: totalPriceFormatter
},
{
field: 'owner',
title: 'Owner',
sortable: true,
align: 'center',
footerFormatter: totalPriceFormatter
}, {
field: 'dept',
title: 'Department',
sortable: true,
align: 'center',
footerFormatter: totalPriceFormatter
},
{
field: 'operate',
title: 'Operations',
align: 'center',
clickToSelect: false,
events: window.operateEvents,
formatter: operateFormatter
},
]
]
})
$table.on('check.bs.table uncheck.bs.table ' +
'check-all.bs.table uncheck-all.bs.table',
function () {
$remove.prop('disabled', !$table.bootstrapTable('getSelections').length)
// save your data, here just save the current page
selections = getIdSelections()
// push or splice the selections if you want to save all data selections
})
$table.on('all.bs.table', function (e, name, args) {
console.log(name, args)
})
$remove.click(function () {
var ids = getIdSelections()
$table.bootstrapTable('remove', {
field: 'id',
values: ids
})
$remove.prop('disabled', true)
})
}
$(function() {
initTable()
$('#locale').change(initTable)
})
</script>