pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <i id='zQHfm'><tr id='zQHfm'><dt id='zQHfm'><q id='zQHfm'><span id='zQHfm'><b id='zQHfm'><form id='zQHfm'><ins id='zQHfm'></ins><ul id='zQHfm'></ul><sub id='zQHfm'></sub></form><legend id='zQHfm'></legend><bdo id='zQHfm'><pre id='zQHfm'><center id='zQHfm'></center></pre></bdo></b><th id='zQHfm'></th></span></q></dt></tr></i><div class="pxnrbdp" id='zQHfm'><tfoot id='zQHfm'></tfoot><dl id='zQHfm'><fieldset id='zQHfm'></fieldset></dl></div>
    • <bdo id='zQHfm'></bdo><ul id='zQHfm'></ul>

  • <small id='zQHfm'></small><noframes id='zQHfm'>

    <tfoot id='zQHfm'></tfoot>

        <legend id='zQHfm'><style id='zQHfm'><dir id='zQHfm'><q id='zQHfm'></q></dir></style></legend>

        在 GridView Yii2 中對(duì)數(shù)據(jù)進(jìn)行排序和過濾,其中列

        Sort and filter data in GridView Yii2 where column is not in database(在 GridView Yii2 中對(duì)數(shù)據(jù)進(jìn)行排序和過濾,其中列不在數(shù)據(jù)庫中)
            <i id='xeCBM'><tr id='xeCBM'><dt id='xeCBM'><q id='xeCBM'><span id='xeCBM'><b id='xeCBM'><form id='xeCBM'><ins id='xeCBM'></ins><ul id='xeCBM'></ul><sub id='xeCBM'></sub></form><legend id='xeCBM'></legend><bdo id='xeCBM'><pre id='xeCBM'><center id='xeCBM'></center></pre></bdo></b><th id='xeCBM'></th></span></q></dt></tr></i><div class="9v1bfjn" id='xeCBM'><tfoot id='xeCBM'></tfoot><dl id='xeCBM'><fieldset id='xeCBM'></fieldset></dl></div>

            <tfoot id='xeCBM'></tfoot>
            <legend id='xeCBM'><style id='xeCBM'><dir id='xeCBM'><q id='xeCBM'></q></dir></style></legend>
              <tbody id='xeCBM'></tbody>
              <bdo id='xeCBM'></bdo><ul id='xeCBM'></ul>
            • <small id='xeCBM'></small><noframes id='xeCBM'>

                  本文介紹了在 GridView Yii2 中對(duì)數(shù)據(jù)進(jìn)行排序和過濾,其中列不在數(shù)據(jù)庫中的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  如果我在 db 中有 2 個(gè)字段 - 概率和影響,并且我需要 GridView 中的一列,其中這兩個(gè)字段相乘.我設(shè)法將它添加到那里:

                  If I have 2 fields in db - probability and influence and I need a column in GridView where these two fields are multiplied. I managed to add it there like:

                      [
                              'attribute' => 'priority',
                              'format' => 'raw',
                              'value' => function ($model) {
                                  return $model->influence * $model->probability;
                              },
                          ],
                  

                  但無法處理排序,因?yàn)樵摿胁辉跀?shù)據(jù)庫中,向 $query 添加過濾器只會(huì)導(dǎo)致錯(cuò)誤.

                  But can't handle the sorting, because that column is not in db and adding filters to $query causes only errors.

                      $query = Risks::find();
                      $query->select(`probability*influence AS priority`);
                      $dataProvider = new ActiveDataProvider([
                          'query' => $query,
                      ]);
                  

                  已更新(適用于 Asc 和 Desc 但不適用于過濾器)

                  Updated (works Asc and Desc but not with filters)

                  public function search($params)
                  {
                      $query = Risks::find();
                  
                      $query->joinWith(['author', 'proj']);
                  
                      $query->select('*, (probability * influence) as priority');
                  
                      $dataProvider = new ActiveDataProvider([
                          'query' => $query,
                      ]);
                  
                      $dataProvider->setSort([
                          'attributes' => [
                             // 'id',
                              'probability',
                              'risks',
                              'influence',
                              'del' => [
                                  'asc' => ['risks.del' => SORT_ASC],
                                  'desc' => ['risks.del' => SORT_DESC],
                              ],
                              'priority' => [
                                  'asc' => ['priority' => SORT_ASC],
                                  'desc' => ['priority' => SORT_DESC],
                                  'label' => 'Priority',
                              ],
                              'proj' => [
                                  'asc' => ['projects.name' => SORT_ASC],
                                  'desc' => ['projects.name' => SORT_DESC],
                              ],
                              'author' => [
                                  'asc' => ['users.name' => SORT_ASC],
                                  'desc' => ['users.name' => SORT_DESC],
                              ]
                          ]
                      ]);
                  
                      $this->load($params);
                  
                      if (!$this->validate()) {
                          // uncomment the following line if you do not want to any records when validation fails
                          // $query->where('0=1');
                          return $dataProvider;
                      }
                  
                  
                      $query->andFilterWhere([
                          'id' => $this->id,
                          'proj_id' => $this->proj_id,
                          'author_id' => $this->author_id,
                          'influence' => $this->influence,
                          'probability' => $this->probability,
                          //'del' => $this->del,
                      ])
                          ->andFilterWhere(['like', 'projects.name', $this->proj])
                          ->andFilterWhere(['like', 'users.name', $this->author]);
                  
                      $query->andFilterWhere(['like', 'risks', $this->risks]);
                  
                      $query->having('priority = '. $this->priority);
                      //$query->having(['priority' => $this->priority]);
                  
                      return $dataProvider;
                  }
                  

                  推薦答案

                  第 1 步:將 getter 函數(shù)添加到您的基本 Risks 模型:

                  STEP 1: Add a getter function to your base Risks model:

                  public function getPriority() {
                      return ($this->probability * $this->influence);
                  }
                  

                  第 2 步:將屬性 priority 添加到您的模型 RisksSearch 并配置您的規(guī)則.

                  STEP 2: Add an attribute priority to your model RisksSearch and configure your rules.

                  /* your calculated attribute */
                  public $priority;
                  
                  /* setup rules */
                  public function rules() {
                     return [
                         /* your other rules */
                         [['priority'], 'safe']
                     ];
                  }
                  

                  第 3 步:編輯 search() 方法以包含計(jì)算字段 priority

                  public function search($params) {
                  
                      $query = Person::find();
                  
                      $query->select('*, (probability * influence) as priority');
                  
                      $dataProvider = new ActiveDataProvider([
                          'query' => $query,
                      ]);
                  
                      /**
                       * Setup your sorting attributes
                       * Note: This is setup before $this->load($params)
                       */
                      $dataProvider->setSort([
                          'attributes' => [
                              'id',
                              'priority' => [
                                  'asc' => ['priority' => SORT_ASC],
                                  'desc' => ['priority' => SORT_DESC],
                                  'label' => 'Priority',
                                  'default' => SORT_ASC
                              ],
                          ]
                      ]);
                      ...
                  

                  第 4 步:在 $this->load($params) 之后添加 $query->andFilterWhere() 以便能夠過濾計(jì)算出的字段

                  STEP 4: Add $query->andFilterWhere() after $this->load($params) to be able to filter the calculated field

                  // use the operator you wish, i.e. '=', '>', '<' etc
                  $query->andFilterWhere(['=', '(probability * influence)', $this->priority]);
                  

                  這篇關(guān)于在 GridView Yii2 中對(duì)數(shù)據(jù)進(jìn)行排序和過濾,其中列不在數(shù)據(jù)庫中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  enable SOAP on PHP(在 PHP 上啟用 SOAP)
                  Get received XML from PHP SOAP Server(從 PHP SOAP 服務(wù)器獲取接收到的 XML)
                  not a valid AllXsd value(不是有效的 AllXsd 值)
                  PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 異常無法連接到主機(jī))
                  Implementation of P_SHA1 algorithm in PHP(PHP中P_SHA1算法的實(shí)現(xiàn))
                  Sending a byte array from PHP to WCF(將字節(jié)數(shù)組從 PHP 發(fā)送到 WCF)

                    <i id='i5GZ9'><tr id='i5GZ9'><dt id='i5GZ9'><q id='i5GZ9'><span id='i5GZ9'><b id='i5GZ9'><form id='i5GZ9'><ins id='i5GZ9'></ins><ul id='i5GZ9'></ul><sub id='i5GZ9'></sub></form><legend id='i5GZ9'></legend><bdo id='i5GZ9'><pre id='i5GZ9'><center id='i5GZ9'></center></pre></bdo></b><th id='i5GZ9'></th></span></q></dt></tr></i><div class="d3flffz" id='i5GZ9'><tfoot id='i5GZ9'></tfoot><dl id='i5GZ9'><fieldset id='i5GZ9'></fieldset></dl></div>
                  1. <small id='i5GZ9'></small><noframes id='i5GZ9'>

                      <tbody id='i5GZ9'></tbody>

                            <bdo id='i5GZ9'></bdo><ul id='i5GZ9'></ul>

                            <legend id='i5GZ9'><style id='i5GZ9'><dir id='i5GZ9'><q id='i5GZ9'></q></dir></style></legend>
                            <tfoot id='i5GZ9'></tfoot>
                          • 主站蜘蛛池模板: 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 农产品溯源系统_农产品质量安全追溯系统_溯源系统 | 厌氧反应器,IC厌氧反应器,厌氧三相分离器-山东创博环保科技有限公司 | 中央空调温控器_风机盘管温控器_智能_液晶_三速开关面板-中央空调温控器厂家 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 | 无轨电动平车_轨道平车_蓄电池电动平车★尽在新乡百特智能转运设备有限公司 | 盘煤仪,盘料仪,盘点仪,堆料测量仪,便携式激光盘煤仪-中科航宇(北京)自动化工程技术有限公司 | 哲力实业_专注汽车涂料汽车漆研发生产_汽车漆|修补油漆品牌厂家 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 热处理温控箱,热处理控制箱厂家-吴江市兴达电热设备厂 | 办公室家具公司_办公家具品牌厂家_森拉堡办公家具【官网】 | 胶辊硫化罐_胶鞋硫化罐_硫化罐厂家-山东鑫泰鑫智能装备有限公司 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 骁龙云呼电销防封号系统-axb电销平台-外呼稳定『免费试用』 | 智慧水务|智慧供排水利信息化|水厂软硬件系统-上海敢创 | 中开泵,中开泵厂家,双吸中开泵-山东博二泵业有限公司 | CNC机加工-数控加工-精密零件加工-ISO认证厂家-鑫创盟 | 油漆辅料厂家_阴阳脚线_艺术漆厂家_内外墙涂料施工_乳胶漆专用防霉腻子粉_轻质粉刷石膏-魔法涂涂 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 洛阳永磁工业大吊扇研发生产-工厂通风降温解决方案提供商-中实洛阳环境科技有限公司 | 阴离子_阳离子聚丙烯酰胺厂家_聚合氯化铝价格_水处理絮凝剂_巩义市江源净水材料有限公司 | 称重传感器,测力传感器,拉压力传感器,压力变送器,扭矩传感器,南京凯基特电气有限公司 | 武汉创亿电气设备有限公司_电力检测设备生产厂家| 新型游乐设备,360大摆锤游乐设备「诚信厂家」-山东方鑫游乐设备 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 宿松新闻网 宿松网|宿松在线|宿松门户|安徽宿松(直管县)|宿松新闻综合网站|宿松官方新闻发布 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 间苯二酚,间苯二酚厂家-淄博双和化工| 南方珠江-南方一线电缆-南方珠江科技电缆-南方珠江科技有限公司 南汇8424西瓜_南汇玉菇甜瓜-南汇水蜜桃价格 | 断桥铝破碎机_铝合金破碎机_废铁金属破碎机-河南鑫世昌机械制造有限公司 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | 艺术漆十大品牌_艺术涂料加盟代理_蒙太奇艺术涂料厂家品牌|艺术漆|微水泥|硅藻泥|乳胶漆 | 工作心得_读书心得_学习心得_找心得体会范文就上学道文库 | 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | 上海软件开发-上海软件公司-软件外包-企业软件定制开发公司-咏熠科技 | 304不锈钢无缝管_不锈钢管厂家 - 隆达钢业集团有限公司 | 温州富欧金属封头-不锈钢封头厂家 | 新疆乌鲁木齐网站建设-乌鲁木齐网站制作设计-新疆远璨网络 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 软文世界-软文推广-软文营销-新闻稿发布-一站式软文自助发稿平台 | 【电子厂招聘_普工招工网_工厂招聘信息平台】-工立方打工网 |