php - 在 bootgrid 中使用自定义请求处理程序后搜索短语不起作用

标签 php mysql jquery-bootgrid

我已经为下表实现了 bootgrid,但在使用自定义请求处理程序后,搜索短语不起作用。这是表格。

<div class="table-responsive">
    <table id="product_data" class="table table-bordered table-hover">
        <thead>
        <tr>

            <th data-column-id="sbranch" data-header-align="center" data-align="left">Branch</th>
            <th data-column-id="subject_code" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Code</th>
            <th data-column-id="sname" data-header-align="center" data-align="left">Subject Name</th>
            <th data-column-id="smode" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Mode</th>
            <th data-column-id="ssemester" data-header-align="center" data-align="center" data-order="asc" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Semester</th>
            <th data-column-id="stype" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Type</th>
            <th data-column-id="scredit" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Credit</th>
            <th data-column-id="sslot" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Slot</th>
            <th data-column-id="syear" data-header-align="center" data-align="center" data-css-class="hidden-xs hidden-sm" 
            data-header-css-class="hidden-xs hidden-sm">Year</th>
                        <th data-column-id="commands" data-formatter="commands" data-sortable="false" data-align="center" data-header-align="center">Download</th>
        </tr>
        </thead>
    </table>
    </div>

这是用于加载的请求处理程序

        var productTable = $('#product_data').bootgrid({

        //navigation: 0,
        ajax: true,

        method:"POST",

        requestHandler: function (request) {
               //Add your id property or anything else
                request.branch = $("#branch").val();

               request.id = "b0df282a-0d67-40e5-8558-c9e93b7befed";
               return request;
        },
        url: "sylfetch2.php",

    });
$('#product_data').bootgrid('reload');

这是从表中获取数据的代码

<?php
//fetch.php
include("dbbranch.php");

$sbranch = mysqli_real_escape_string($bmysqli,$_POST["branch"]);

$query = '';
$data = array();
$records_per_page = 10;
$start_from = 0;
$current_page_number = 0;
if(isset($_POST["rowCount"]))
{
 $records_per_page = $_POST["rowCount"];
}
else
{
 $records_per_page = 10;
}
if(isset($_POST["current"]))
{
 $current_page_number = $_POST["current"];
}
else
{
 $current_page_number = 1;
}
$start_from = ($current_page_number - 1) * $records_per_page;
$query .= "
  SELECT 
  * FROM subject WHERE (
        sbranch = '".$sbranch."' )";


if(!empty($_POST["searchPhrase"]))
{
    $query .= 'WHERE (subject.sid LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.sbranch LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.ssemester LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.sslot LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.stype LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.scredit LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.subject_code LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.sname LIKE "%'.$_POST["searchPhrase"].'%" ';
    $query .= 'OR subject.smode LIKE "%'.$_POST["searchPhrase"].'%" ) ';
}
$order_by = '';
if(isset($_POST["sort"]) && is_array($_POST["sort"]))
{
 foreach($_POST["sort"] as $key => $value)
 {
  $order_by .= " $key $value, ";
 }
}
else
{
 $query .= 'ORDER BY subject.sid DESC ';
}
if($order_by != '')
{
 $query .= ' ORDER BY ' . substr($order_by, 0, -2);
}

if($records_per_page != -1)
{
 $query .= " LIMIT " . $start_from . ", " . $records_per_page;
}
//echo $query;
$result = mysqli_query($bmysqli, $query);
while($row = mysqli_fetch_assoc($result))
{
 $data[] = $row;
}

$query1 = "SELECT * FROM subject WHERE (
        sbranch = '".$sbranch."' ) ";
$result1 = mysqli_query($bmysqli, $query1);
$total_records = mysqli_num_rows($result1);

$output = array(
 'current'  => intval($_POST["current"]),
 'rowCount'  => 10,
 'total'   => intval($total_records),
 'rows'   => $data
);

echo json_encode($output);

?>

使用此请求处理程序后,每当我输入任何搜索时,表格就会卡在加载时。

最佳答案

您应该以这种方式传递自定义请求对象中的属性:

    ... //Rest of code skipped for brevety
    requestHandler: function (request) {
        var model = {
        Current: request.current,
        RowCount: request.rowCount,
        Search: request.searchPhrase,
        Branch: $("#branch").val(),
        Id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
        };

        //You could need this. Otherwise, skip...
        for (var key in request.sort) {
            model.SortBy = key;
            model.SortDirection = request.sort[key];
        };

        return JSON.stringify(model);
    },
    ....// the rest of code...

关于php - 在 bootgrid 中使用自定义请求处理程序后搜索短语不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44974177/

相关文章:

mysql - 如何使用 SQL 执行可选 JOIN

php - 处理级联碰撞?

php - 打包通用 zend 模块的最佳方式

php - 无效使用组函数的初学者 MySQL 问题

mysql - 实时 IAX 客户端问题 Asterisk

jquery bootgrid 与 requestHandler/post 重新加载有关的问题

php - JQUERY Bootgrid 表列表的 mysql 查询中的印度货币格式

Angular2 渲染后执行方法(Bootgrid)

php - 在 PHP 数组中搜索和替换值

php - 并且在子句中不起作用