提问人:tejaswini bnvl 提问时间:8/1/2023 最后编辑:CBroetejaswini bnvl 更新时间:8/2/2023 访问量:33
我想使用jquery将会话值存储在appTables的搜索框中
I want to store the session value in search box of appTables using jquery
问:
我想使用jquery将会话值存储在appTables的搜索框中
<?php $session = \Config\Services::session(); ?>
<script type="text/javascript">
$(document).ready(function () {
var searchVals = "<?php echo $session->get('search_by_val'); ?>";
$("#lead-table").appTable({
source: '<?php echo_uri("leads/list_data") ?>',
serverSide: true,
bStateSave: true,
additionalData: { search_value: searchVals }
});
});
</script>
在此 searchVals 中,变量应传递到 additionalData 方法中,当它重新加载时,它应该按照搜索参数工作。
答:
0赞
AdityaDees
8/1/2023
#1
您需要为搜索框输入添加事件处理程序,以便每当用户键入或更改搜索值时,它都会更新会话变量并重新加载 appTable。
<?php $session = \Config\Services::session(); ?>
<script type="text/javascript">
$(document).ready(function () {
// Function to reload appTable with the updated search value
function reloadTable() {
var searchVals = "<?php echo $session->get('search_by_val'); ?>";
$("#lead-table").appTable({
source: '<?php echo_uri("leads/list_data") ?>',
serverSide: true,
bStateSave: true,
additionalData: { search_value: searchVals }
});
}
// Get the initial search value from the session and reload the table
reloadTable();
// Add an event handler for the search box
$("#search-box").on('input', function () {
var searchValue = $(this).val();
// Update the session variable with the new search value using AJAX
$.ajax({
url: '<?php echo_uri("your/update/session/endpoint") ?>',
method: 'POST',
data: { search_by_val: searchValue },
success: function () {
// Reload the appTable with the updated search value
reloadTable();
}
});
});
});
</script>
评论
0赞
tejaswini bnvl
8/2/2023
我试过了,但它没有加载带有搜索标签的数据表
评论
var searchVals = <?php echo json_encode($session->get('search_by_val'); ?>;