形成此链接:
Bootstrap table filtering not working
我的代码:
<table
data-url="<?php echo Yii::app()->createUrl('sj/getdata_list'); ?>"
data-pagination="true"
id="tables"
class="table table-striped table-hover "
data-toggle="table"
data-side-pagination="server"
data-page-list="[5, 10, 20, 50, 100, 200]"
data-search="true"
data-show-pagination-switch="showPaginationSwitch"
data-filters="true"
data-filter-control="true"
data-sort-order="desc"
data-selectable-rows="true"
data-item-id="id"
data-show-columns="true"
data-selectable-rows-action="load_panels"
data-minimum-count-columns="1"
data-show-refresh="true"
data-search-align="left"
data-toolbar="#Customer-custom-toolbar"
data-show-filter="true"
data-striped="true"
data-sort-name="id"
data-show-toggle="true"
data-detail-view="true"
data-detail-formatter="detailFormatter"
data-id-field="no_sj"
data-editable-emptytext="-"
data-editable-url="<?php echo Yii::app()->createUrl('sj/edit_sj');?>"
data-filter-control="true"
>
<caption style="border: inherit; background-color: lightgrey;">
<span class="align-left"><strong>Tabel Pembelian yang belum diterima</strong></span>
</caption>
<thead>
<tr>
<th data-field="no_sj" data-sortable="true" data-filter-control="input">No Surat Jalan</th>
<th data-field="tgl_sj" data-sortable="true" data-filter-control="select">Tgl Surat Jalan</th>
<th data-field="cabang" data-sortable="true" data-filter-control="input">Cabang</th>
<th data-field="qnty" data-sortable="true">Quantity</th>
<th data-field="harga" data-sortable="true" class="hidden">Harga</th>
<th data-field="jt" data-sortable="true">JT</th>
<th data-field="stat_terima" data-sortable="true" data-filter-control="select" class='set_edit_status' data-editable-title='Status :' data-pk='no_sj' data-editable="true">Status</th>
<th data-field="tgl_terima" data-sortable="true" data-filter-control="datepicker" class='set_edit_tanggal' data-editable-type="date" data-editable-viewformat='dd-mm-yyyy' data-editable-clear='false' data-editable-format='dd-mm-yyyy' data-editable-datepicker='{weekStart:1}' data-pk='no_sj' data-editable="true" >Tanggal</th>
<th data-field="ket_terima" data-sortable="true" class="hidden">Ket</th>
</tr>
</thead>
</table>
过滤器中的结果&#34;选择&#34;没有用。 它只显示选择显示的页面,如果在下一页/上一页中,过滤器选择没有出现在选项选择过滤器中。
我还想念别的什么?
答案 0 :(得分:1)
我遇到了同样的问题,并通过编辑bootstrap-table-filter js文件并将其重命名为我的页面上的一个off来提出hackey解决方案。
我没有评论第65行:
selectControl = $(selectControl.get(0));
取而代之(从208行开始?):
if (column.filterData !== undefined && column.filterData.toLowerCase() !== 'column') {
var filterDataType = column.filterData.substring(0, 3);
var filterDataSource = column.filterData.substring(4, column.filterData.length);
var selectControl = $('.' + column.field);
addOptionToSelectControl(selectControl, '', '');
switch (filterDataType) {
case 'url':
$.ajax({
url: filterDataSource,
dataType: 'json',
success: function (data) {
$.each(data, function (key, value) {
addOptionToSelectControl(selectControl, key, value);
});
}
});
有了这个:
if (column.filterControl && column.searchable) {
var filterDataType = 'url';
var filterDataSource = 'fema_filter_data.php?column='+column.field;
var selectControl = $('.' + column.field);
switch (filterDataType) {
case 'url':
$.ajax({
url: filterDataSource,
dataType: 'json',
success: function (data) {
$.each(data, function (key, value) {
if(column.field === 'team'){
addOptionToSelectControl(selectControl,value.team, value.team);
}
if(column.field === 'city'){
addOptionToSelectControl(selectControl,value.city, value.city);
}
if(column.field === 'st_name'){
addOptionToSelectControl(selectControl,value.st_name, value.st_name);
}
if(column.field === 'residence'){
addOptionToSelectControl(selectControl,value.residence, value.residence);
}
if(column.field === 'type_abbr'){
addOptionToSelectControl(selectControl,value.type_abbr, value.type_abbr);
}
if(column.field === 'own_rent'){
addOptionToSelectControl(selectControl,value.own_rent, value.own_rent);
}
if(column.field === 'cat'){
addOptionToSelectControl(selectControl,value.cat, value.cat);
}
});
}
});
break;
.each中的条件是我想要过滤的列。 然后我不得不评论整个块(从大约400开始?):
if ((!column.checkbox) || (!column.radio)) {
if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select' && column.searchable) {
if (column.filterData === undefined || column.filterData.toLowerCase() === 'column') {
var selectControl = $('.' + column.field);
if (selectControl !== undefined && selectControl.length > 0) {
if (selectControl.get(0).options.length === 0) {
//Added the default option
addOptionToSelectControl(selectControl, '', '');
}
//Added a new value
addOptionToSelectControl(selectControl, value, value);
}
}
}
}
因为它覆盖了我的价值观。 fema_filter_data.php是一个专门设置为拉取过滤器值并返回json的页面:
if($_GET['column'] == 'st_name'){
$sql = "select trim(st_name) as st_name FROM v_idam_damaged_parcels dp
WHERE (".$damage_type." > 0 OR boot_type = 'IA')
AND dp.event_id = '".$_SESSION['event_id']."'
AND num_buildings > 0
group by st_name order by st_name";
}
if($_GET['column'] == 'team'){
$sql = "select trim(t.team_name) as team FROM v_idam_damaged_parcels dp
RIGHT JOIN parcel AS ps ON dp.parcel = ps.qpid
LEFT JOIN event_team_region AS etr ON st_intersects(etr.the_geom,ps.the_geom) AND etr.event_id = ". $_SESSION['event_id']."
LEFT JOIN teams t on t.team_id = etr.team_id
WHERE (".$damage_type." > 0 OR boot_type = 'IA')
AND dp.event_id = '".$_SESSION['event_id']."'
AND num_buildings > 0
group by t.team_name order by t.team_name";
} 等...
然后:
array_unshift($result,''); // first record showing in filter should be blank
echo json_encode($result);