Skip to content

Commit

Permalink
异步渲染表格
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed May 23, 2021
1 parent 93a427a commit 7463a69
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/views/filter/container.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="filter-box shadow-0 card mb-0 {{ $expand ? '' : 'd-none' }} {{$containerClass}}">
<div class="card-body" style="{!! $style !!}" id="{{ $filterID }}">
<form action="{!! $action !!}" class="form-horizontal" pjax-container method="get">
<form action="{!! $action !!}" class="form-horizontal grid-filter-form" pjax-container method="get">
<div class="row mb-0">
@foreach($layout->columns() as $column)
@foreach($column->filters() as $filter)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filter/right-side-container.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="hidden">
<div class="filter-box right-side-filter-container" style="{!! $style !!}" id="{{ $filterID }}">
<form action="{!! $action !!}" class="form-horizontal" pjax-container method="get">
<form action="{!! $action !!}" class="form-horizontal grid-filter-form" pjax-container method="get">
<div class="mb-1" style="height: 55px">
<div class="p-1 position-fixed d-flex justify-content-between header">
<div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filter/simple-container.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="filter-box card p-2 {{ $expand ? '' : 'd-none' }} {{$containerClass}}" style="padding-bottom: .5rem!important;margin-top: 10px;margin-bottom: 8px;box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.04);">
<div class="card-body" style="{!! $style !!}" id="{{ $filterID }}">
<form action="{!! $action !!}" class="form-horizontal" pjax-container method="get">
<form action="{!! $action !!}" class="form-horizontal grid-filter-form" pjax-container method="get">
<div class="row mt-1 mb-0">
@foreach($layout->columns() as $column)
@foreach($column->filters() as $filter)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/grid/quick-search.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>::-ms-clear,::-ms-reveal{display: none;}</style>

<form action="{!! $action !!}" class="input-no-border d-md-inline-block" pjax-container style="display:none;margin-right: 16px">
<form action="{!! $action !!}" class="input-no-border quick-search-form d-md-inline-block" style="display:none;margin-right: 16px">
<div class="table-filter">
<label style="width: {{ $width }}rem">
<input
Expand Down
5 changes: 5 additions & 0 deletions src/Grid/Concerns/HasFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Support\Helper;
use Illuminate\Support\Collection;

trait HasFilter
Expand Down Expand Up @@ -154,5 +155,9 @@ protected function addFilterScript()
}
JS
);

$url = Helper::fullUrlWithoutQuery(['_pjax']);

Admin::script("$('.grid-filter-form').attr('action', '{$url}');", true);
}
}
12 changes: 12 additions & 0 deletions src/Grid/Concerns/HasQuickSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dcat\Admin\Grid\Concerns;

use Dcat\Admin\Admin;
use Dcat\Admin\Grid\Column;
use Dcat\Admin\Grid\Events\ApplyQuickSearch;
use Dcat\Admin\Grid\Model;
Expand Down Expand Up @@ -49,6 +50,8 @@ public function quickSearch($search = null)
$this->quickSearch = $search;

$search->setGrid($this);

$this->addQuickSearchScript();
});
}

Expand Down Expand Up @@ -324,4 +327,13 @@ protected function addWhereBasicBinding($query, ?string $column, ?bool $or, ?str

Helper::withQueryCondition($query, $column, $method, [$operator, $value]);
}

protected function addQuickSearchScript()
{
if ($this->isAsyncRequest()) {
$url = Helper::fullUrlWithoutQuery(['_pjax']);

Admin::script("$('.quick-search-form').attr('action', '{$url}');", true);
}
}
}

0 comments on commit 7463a69

Please sign in to comment.