tpextbuilder- Search 搜尋

ichynul發表於2021-08-29

其實就是Form,把某些不適合使用的元件隱藏了

/**
 * Methods.
 *
 * Text           text($name, $label = '', $colSize = 2, $filter = '')
 * Checkbox       checkbox($name, $label = '', $colSize = 2, $filter = '')
 * Radio          radio($name, $label = '', $colSize = 2, $filter = '')
 * Button         button($type, $label = '', $colSize = 2, $filter = '')
 * Select         select($name, $label = '', $colSize = 2, $filter = '')
 * MultipleSelect multipleSelect($name, $label = '', $colSize = 2, $filter = '')
 * Textarea       textarea($name, $label = '', $colSize = 2, $filter = '')
 * Hidden         hidden($name)
 * Color          color($name, $label = '', $colSize = 2, $filter = '')
 * RangeSlider    rangeSlider($name, $label = '', $colSize = 2, $filter = '')
 * Date           date($name, $label = '', $colSize = 2, $filter = '')
 * Datetime       datetime($name, $label = '', $colSize = 2, $filter = '')
 * Time           time($name, $label = '', $colSize = 2, $filter = '')
 * Year           year($name, $label = '', $colSize = 2, $filter = '')
 * Month          month($name, $label = '', $colSize = 2, $filter = '')
 * DateRange      dateRange($name, $label = '', $colSize = 2, $filter = '')
 * DateTimeRange  datetimeRange($name, $label = '', $colSize = 2, $filter = '')
 * TimeRange      timeRange($name, $label = '', $colSize = 2, $filter = '')
 * Number         number($name, $label = '', $colSize = 2, $filter = '')
 * SwitchBtn      switchBtn($name, $label = '', $colSize = 2, $filter = '')
 * Rate           rate($name, $label = '', $colSize = 2, $filter = '')
 * Divider        divider($text, $label = '', $colSize = 2, $filter = '')
 * Decimal        decimal($name, $label = '', $colSize = 2, $filter = '')
 * Tags           tags($name, $label = '', $colSize = 2, $filter = '')
 * Icon           icon($name, $label = '', $colSize = 2, $filter = '')
 * Fields         fields($name, $label = '', $colSize = 12, $filter = '')
 */
field引數說明

$name 欄位名稱 必填

$label 顯示label ,不填則取name值

$cloSize col-md-大小,預設:2

$filter 搜尋條件,預設 ‘eq’

###### search常用方法
```php
//設定欄位元素的預設大小,後面建立的元素就不必一個一個去設定大小了。
$search->defaultDisplayerSize(4, 8);

//設定欄位元素預設`col-md`大小
$search->defaultDisplayerColSize(2);

$search相當於一個$form,是$table的一部分。

protected function filterWhere()
{
//根據提交資料返回搜尋條件,此方法可以不手動重寫,會自動生成搜尋條件,沒怎麼測試過,所以還是推薦手寫。
}

protected function buildSearch()
{
    //$search = $table->getSearch();//獲取一個搜尋

    $search = $this->search;

    //頁面頂部快速切換:tabLink。

    $search->tabLink('is_onsasle')->options([1 => '已上架', 2 => '未上架']);

    $search->hidden('is_onsasle');//用一個隱藏欄位接收切換的值,欄位的名稱要和上面tabLink的一樣。

    //$search->select('is_onsasle', '上架')->options([1 => '已上架', 2 => '未上架']);//或者用一個select或radio也行。

    //其他
    $search->text('kwd', '名稱/spu', 3)->maxlength(20);

    $search->select('category_id', '分類', 3)->dataUrl(url('/admin/shopcategory/selectPage'), 'name');

    $search->select('brand_id', '品牌', 3)->dataUrl(url('/admin/shopbrand/selectPage'));
}

addTop / addBottom ,頂部或底部內容

```php
$search->addTop()->content()->fetch(‘demo’);

$search->addBottom()->content()->display(‘{name}’, [‘name’ => ‘jim’]);

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章