<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## addFilter('字段名' [, '選項', '默認選項', '篩選方式']) 表頭篩選是屬于精確篩選。 | 版本 | 改進 | | --- | --- | | 1.0.4 | 新增“篩選方式”參數,支持單選 | | 1.0.6 | 新增addFilterList()方法,支持自定義篩選列表,非讀取數據庫 | ~~~ // 讀取用戶數據 $data_list = Db::name('admin_user')->select(); // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addOrder('id,username') // 添加排序 ->addFilter('id,username') // 添加篩選 ->addColumn('id', 'ID') ->addColumn('username', '用戶名') ->addColumn('nickname', '昵稱') ->addColumn('email', '郵箱') ->addColumn('mobile', '手機號') ->addColumn('create_time', '創建時間') ->setRowList($data_list) // 設置表格數據 ->fetch(); ~~~ 添加好篩選字段后,還需要在查詢數據之前獲取篩選的數據,使用`$this->getMap()`即可。 ~~~ // 獲取排序 $order = $this->getOrder(); // 獲取篩選 $map = $this->getMap(); // 讀取用戶數據 $data_list = Db::name('admin_user')->where($map)->order($order)->select(); // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addOrder('id,username') // 添加排序 ->addFilter('id,username') // 添加篩選 ->addColumn('id', 'ID') ->addColumn('username', '用戶名') ->addColumn('nickname', '昵稱') ->addColumn('email', '郵箱') ->addColumn('mobile', '手機號') ->addColumn('create_time', '創建時間') ->setRowList($data_list) // 設置表格數據 ->fetch(); ~~~ ![](https://box.kancloud.cn/a854b937c2690040971de9445f8d469a_1468x202.png) 點擊字段篩選,彈出對話框,可以選擇要顯示的數據,也可以動態搜索。 ![](https://box.kancloud.cn/65e425b4fe3468250124971209a6a3de_591x581.png) >[danger]注意,點擊篩選后,會默認在當前表查詢結果,如果當前表沒有數據,則查詢結果為空。 ### 使用數組方式 除了可以以字符串的形式填寫要篩選的字段外,還可以用數組的形式。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addFilter(['id','username']) // 添加篩選 ->fetch(); ~~~ ### 指定其他表的字段 同樣的,如果要篩選的字段不在當前表,需指定表名,比如數據是用[視圖查詢](http://www.hmoore.net/manual/thinkphp5/156576)獲得的。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addFilter('admin_action.username,nickname') // 添加篩選 ->fetch(); ~~~ 也可以用數組的方式寫,格式為`'字段名' => '表名'` ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addFilter(['title' => 'admin_action', 'username']) // 添加篩選 ->fetch(); ~~~ 或者 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addFilter(['admin_action.title', 'username']) // 添加篩選 ->fetch(); ~~~ 如果設置的字段別名,也可以指定其他表,并且指定其他字段名,格式為:`字段別名 => '表名.字段名'` ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addFilter(['module_title' => 'admin_module.title']) // 添加篩選 ->fetch(); ~~~ 其中`module_title`是字段別名。 >[info] 具體使用請參考系統的“日志管理”源碼。 還有一種情況,比如某個字段只是代號,真正需要顯示的數據在另外一張表或自己構造的數據。 比如系統的“配置管理”頁面,假設列是這么定義的. ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型'], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->fetch(); ~~~ 顯示的出來的數據大致是這樣的 ![](https://box.kancloud.cn/a320babda1081de87d5ea6d207665f61_1279x476.png) 我們希望用中文來代替這些值,這里我們設置type類型為select(下拉編輯),并設置下拉選項數據config('form_item_type') ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->fetch(); ~~~ >[info] config('form_item_type')是一個一維數組,取出來的數據是這樣的 ~~~ array( "text" => "單行文本" "textarea" => "多行文本" "static" => "靜態文本" "password" => "密碼" "checkbox" => "復選框" "radio" => "單選按鈕" "date" => "日期" "datetime" => "日期+時間" "hidden" => "隱藏" "switch" => "開關" "array" => "數組" "select" => "下拉框" "linkage" => "普通聯動下拉框" "linkages" => "快速聯動下拉框" "image" => "單張圖片" "images" => "多張圖片" "file" => "單個文件" "files" => "多個文件" "ueditor" => "UEditor 編輯器" "wangeditor" => "wangEditor 編輯器" "editormd" => "markdown 編輯器" "icon" => "字體圖標" "tags" => "標簽" "number" => "數字" ) ~~~ 這樣設置之后的最終結果是 ![](https://box.kancloud.cn/1cd480e8a02db10e08e0c3feb66f6e42_1239x504.png) 我們對type字段添加篩選功能 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type') // 添加標題字段篩選 ->fetch(); ~~~ 點擊篩選圖標之后,會發現結果是這樣 ![](https://box.kancloud.cn/745d6699585ec1c956d328a4a989abfc_546x560.png) 因為數據表里面存儲的就是這樣的數據,如果我們希望這些數據也能轉換顯示,那該怎么辦呢? 只要將對應的數據,也就是上面`config('form_item_type')`的一維數組放在第二個參數即可,系統會對應顯示。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type', config('form_item_type')) // 添加標題字段篩選 ->fetch(); ~~~ 最終顯示結果 ![](https://box.kancloud.cn/18a797f1cdfc7a8c5db9fac62313de2a_536x562.png) >[danger]注意,這種寫法只能一個一個寫,下面的寫法是錯誤的 ~~~ ->addFilter('type,title', config('form_item_type')) // 錯誤寫法 ~~~ ### 默認選項 如果需要默認設置篩選,可以使用第三個參數。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('name', [], ['name' => 'web_site_icp,web_site_keyword']) // 添加標題字段篩選 ->fetch(); ~~~ 上面表示初始狀態下,字段篩選默認點亮字段名為name的字段,并且選中值為web_site_icp和web_site_keyword的選項。 ![](https://box.kancloud.cn/f5673a503bf2a3b28ef17a7cfd379d80_1094x599.png) **也可以指定多個字段** ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('title', [], ['name' => 'web_site_icp,web_site_keyword', 'title' => ['備案信息']]) // 添加標題字段篩選 ->fetch(); ~~~ **指定當前表的其他字段名** ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type', config('form_item_type'), ['title|title2' => ['備案信息']]) // 添加標題字段篩選 ->fetch(); ~~~ 以上表示點亮字段為title的列,但是查詢數據實際查詢的不是title字段,而是title2字段。 **指定其他表的其他字段名** ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type', config('form_item_type'), ['title|admin_article.title' => ['備案信息']]) // 添加標題字段篩選 ->fetch(); ~~~ 以上表示點亮字段為title的列,但是查詢數據實際查詢的是admin_article表的title字段。 >[danger] 注意,設置**默認選項**只是頁面上點亮指定的字段列,并選中指定的字段值,實際查詢的時候,需要自己添加查詢條件。比如默認選擇name字段的web_site_icp和web_site_keyword,那么在查詢時需將條件先設定好。 ~~~ // 設置查詢條件 $map = $this->getMap(); if (empty($map)) { // 默認情況下,查詢name字段的值為web_site_icp和web_site_keyword $map['name'] = ['in', 'web_site_icp,web_site_keyword']; } // 查詢數據 $data_list = ConfigModel::where($map)->paginate(); // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type', config('form_item_type'), ['name' => 'web_site_icp,web_site_keyword']) // 添加標題字段篩選 ->fetch(); ~~~ ### 篩選方式 從1.0.4版本開始,字段篩選支持單選方式,只要添加第四個參數為“`radio`”即可 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilter('type', [], [], 'radio') // 添加標題字段篩選 ->fetch(); ~~~ ## addFilterList('字段名', '需要顯示的列表' [, '默認選項', '篩選方式']) >[info] ## 此方法1.0.6版本開始支持。 用法和addFilter類似,第二個參數填寫一個一維數組即可,數組的key為要查詢的內容,value為顯示的內容。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilterList('status', ['關閉', '開啟']) ->fetch(); ~~~ ![](https://box.kancloud.cn/467d33edb5e241f4bab81070b1b22783_554x549.png) ### 默認值 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilterList('status', ['關閉', '開啟'], '0') ->fetch(); ~~~ ![](https://box.kancloud.cn/8f1a46c0159f2c73c35e1596e7231485_535x551.png) 如果多個默認值,可以使用逗號隔開,或者使用數組形式。 ~~~ ->addFilterList('status', ['關閉', '開啟'], '0,1') 或者 ->addFilterList('status', ['關閉', '開啟'], [0,1]) ~~~ ### 篩選方式 默認為多選,可以改為單選。 ~~~ // 使用ZBuilder構建數據表格 return ZBuilder::make('table') ->addColumns([ // 批量添加數據列 ['name', '名稱', 'text.edit'], ['title', '標題', 'text.edit'], ['type', '類型', 'select', config('form_item_type')], ['status', '狀態', 'switch'], ['sort', '排序', 'text.edit'], ['right_button', '操作', 'btn'] ]) ->addFilterList('status', ['關閉', '開啟'], '', 'radio') ->fetch(); ~~~ ![](https://box.kancloud.cn/72523d2aad76ba832bcae1838193ce5e_529x546.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看