数据表全局过滤无法正常工作

问题描述 投票:0回答:1

问题摘要

yajra数据表中用于全局过滤的默认搜索字段,仅过滤一个第一列,而不过滤其他字段。尝试时,返回“ 未找到匹配项>>”。对自定义的“已添加”或“已编辑”列的过滤不再起作用。.我找不到问题。

问题代码段

在控制器功能中:
$invoices = Invoice::where('branchid', 1)->where('status', 1)->with('branch', 'customer')->withCount(['Sales', 'ImmediateSales']);
            return Datatables::of($invoices)
                ->editColumn('branchid', function ($invoice) {
                    return $invoice->branch->branchname;
                })
                ->editColumn('customer_id', function ($invoice) {
                    return $invoice->customer->name;
                })
                ->addColumn('total', function ($invoice) {
                    $total = $invoice->totalamount + $invoice->vatamount - $invoice->offeramount - $invoice->discount - $invoice->rebate;
                    return $total;
                })
                ->addColumn('due', function ($invoice) {
                    $due = $invoice->due;
                    if ($due > 0) {
                        if ($invoice->due_omitted) {
                            $due = "<del>$due</del>";
                        }
                        $due ="<span class='label-danger' title='Due Omitted'> $due </span>";
                    }
                    return $due;
                })
                ->addColumn('type', function ($invoice) {
                     $type = null;
                     if (($invoice->sales_count) && ($invoice->immediate_sales_count)) {
                         $type = "Both";
                     }else if (($invoice->sales_count) && !($invoice->immediate_sales_count)) {
                         $type = "Normal";
                     } else if (!($invoice->sales_count) && ($invoice->immediate_sales_count)) {
                         $type = "Immediate";
                     }
                    return $type;
                })
                ->addColumn('created_at', function ($invoice) {
                     return "<span data-title='".Carbon::parse($invoice->created_at)->format('h:m A')."'>".Carbon::parse($invoice->created_at)->format('d M Y')."</span>";
                })
                ->addColumn('action', function ($invoice) {
                    $btn = '<div class="table-actions text-right">';
                    if(Auth::user()->can("invoice-view")){
                        $btn .= '<button type="button" class="btn btn-primary btn-xs view-btn" data-toggle="modal" data-target="#product-details" value="'.$invoice->invoiceid.'"><i class="fa fa-eye" aria-hidden="true"></i> View</button>';
                    }
                    if(Auth::user()->can("invoice-print")) {
                        $btn .= ' <a href="/print-invoice/' . $invoice->invoiceid . '" class="btn btn-warning btn-xs" aria-hidden="true" target="_blank"><i class="fa fa-print" aria-hidden="true"></i>Print</a> ';
                    }
                    if (!$invoice->historyId && $invoice->qty && Auth::user()->can('sale-return')) {
                        $btn .= ' <a type="button" href="/return-invoice/'.$invoice->invoiceid.'" class="btn btn-info btn-xs" data-dismiss="modal" aria-hidden="true"><i class="fa fa-reply" aria-hidden="true"></i> Return</a> ';
                    }
                    if(Auth::user()->can("invoice-delete")) {
                        $btn .= ' <button class="btn btn-danger btn-xs delete-btn" data-dismiss="modal" aria-hidden="true" value="'.$invoice->invoiceid.'"><i class="fa fa-eye-slash" aria-hidden="true"></i> Delete </button> ';
                    }
                    $btn .= '</div>';
                    return $btn;
                })
                ->rawColumns(['due','created_at', 'action'])
                ->make(true);

在刀片文件中:

<table  id="allInvoiceTBL" class="table table-hover table-responsive ">
    <thead>
                <th>Id</th>
                <th>Branch</th>
                <th>Customer</th>
                <th>Total</th>
                <th>Due</th>
                <th>Type</th>
                <th>Date</th>
                <th class="text-center"> Action</th>
    </thead>
    <tbody>
    </tbody>
    <tfoot>
    </tfoot>
</table>
$('#allInvoiceTBL').DataTable({
                        processing: true,
                        serverSide: true,
                        ajax: "{{ route('invoice-all') }}",
                        deferRender: true,
                        order: [[0, "desc"]],
                        columns: [
                            {data: 'invoiceid', name: 'invoiceid'},
                            {data: 'branchid', name: 'branchid'},
                            {data: 'customer_id', name: 'customer_id'},
                            {data: 'total', name: 'total'},
                            {data: 'due', name: 'due'},
                            {data: 'type', name: 'type'},
                            {data: 'created_at', name: 'created_at'},
                            {data: 'action', name: 'action', orderable: false, searchable: false},
                        ]
                    });

我的系统配置:

  • PHP版本:7.2.12
  • Laravel版本:5.7.28
  • Laravel-Datatables版本:8.13.7

问题摘要yajra数据表中用于全局过滤的默认搜索字段,仅过滤一个第一列而不过滤其他列。尝试时,返回“找不到匹配项”。对自定义“已添加或已编辑...”进行过滤...] >>

我认为这是因为只有您的orderId来自您的主表...另一个来自您的关系模型...数据表仅搜索:: of()我猜是传递的内容]

laravel datatables yajra-datatable laravel-datatables
1个回答
0
投票

我认为这是因为只有您的orderId来自您的主表...另一个来自您的关系模型...数据表仅搜索:: of()我猜是传递的内容]

© www.soinside.com 2019 - 2024. All rights reserved.