提问人:Glenn Coco 提问时间:6/27/2023 最后编辑:Glenn Coco 更新时间:6/28/2023 访问量:38
在不同条目上筛选数据表时出错
Error on Filtering data table on different entry
问:
当我筛选特定行(假设第 14 行)的数据时,我的当前视图仅显示 10 个条目,它不会显示第 14 行。但是,如果我将每个视图的条目数增加到 25,则第 14 行将变为可见。在这种情况下,我当前的视图或显示设置似乎限制了一次显示的行数。
我目前使用的数据表来自 Sufee Admin Template,似乎该模板已经在分页中构建。以下是我更新的观点:
<div class="card-body">
<table class="table table-bordered table-sm" id="content">
<thead>
<tr style="background-color:#DDDDDD;">
<th>#</th>
<th>Category Title</th>
<th>Content Type</th>
<th>Desc</th>
<th>Icon </th>
<th class="text-center"> Link</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
if (!empty($rsContent)) {
foreach ($rsContent as $key => $row) {
?>
<tr data-category="<?php echo $row['title']; ?>" data-content-type="<?php echo ($row['content_type'] == '1') ? 'image' : 'video'; ?>">
<td>
<?php echo $i++; ?>
</td>
<td>
<?php echo $row['title']; ?>
</td>
<td>
<?php if ($row['content_type'] == '1') { ?>
<i class="fa fa-picture-o"></i>
<?php echo "Image"; ?>
<?php } else { ?>
<i class="fa fa-youtube-play"></i>
<?php echo "Video";
}
?>
</td>
<td>
<?php echo $row['desc']; ?>
</td>
<td>
<?php echo $row['icon']; ?>
</td>
<td>
<?php echo $row['image']; ?>
<?php echo $row['link']; ?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
function applyFilter() {
var filterCategory = $('#filter_category').val();
var filterContentType = $('#filter_content_type').val();
$('#content tbody tr').hide();
if (filterCategory != '' || filterContentType != '') {
$('#content tbody tr').each(function () {
var category = $(this).data('category');
var contentType = $(this).data('content-type');
if (
(filterCategory == '' || category == filterCategory) &&
(filterContentType == '' || contentType == filterContentType)
) {
$(this).show();
}
});
} else {
$('#content tbody tr').show();
}
$.ajax({
url: 'e_learning/admin/content',
type: 'POST',
data: {
category: filterCategory,
content_type: filterContentType
},
success: function (response) {
$('#content-list').html(response);
},
error: function (xhr, status, error) {
console.error(error);
}
});
}
<div class="card-body bg-dark-transparent" id="form_collapse_list_0" style="">
<div class="table-responsive bg-white p-2">
<div id="table_forms_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4 no-footer">
<div class="tab-pane fade active show" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
<div class="form-row">
<div class="form-group col-md-6">
<label for="filter_category">Category:</label>
<div class="d-flex align-items-center">
<select class="form-control" id="filter_category">
<option value="">All Categories</option>
<?php foreach ($rsFilterCategory as $key => $row) {
$selected = (!empty($filter_category) && $filter_category == $row['title']) ? 'selected' : '';
echo '<option value="' . $row["title"] . '" data-category="' . $row["title"] . '" ' . $selected . '>' . $row["title"] . '</option>';
} ?>
</select>
</div>
</div>
<div class="form-group col-md-6">
<label for="filter_content_type">Content Type:</label>
<div class="d-flex align-items-center">
<select class="form-control" id="filter_content_type">
<option value="">All Types</option>
<option value="image">Image</option>
<option value="video">Video</option>
</select>
</div>
</div>
</div>
<div class="float-right">
<button class="btn btn-success rounded" onclick="applyFilter()">Apply Filter</button>
<button class="btn btn-warning rounded" onclick="clearFilter()">Clear Filter</button>
</div>
</div>
</div>
</div>
</div>
答: 暂无答案
评论
e_learning/admin/content