October CMS resources and help articles

Simple and to the point. Optimized by the community.

Search for translated values in a backend list

1
by OFFLINE, last modified on August 12th, 2019

By default, contents of RainLab.Translate are not regarded when a search is started in a backend list. Add the following listExtendRecords method to your Controller to also search for certain translated fields (in this case the name field in a fr locale).

    public function listExtendRecords($records)
    {
       $searchTerm = $this->widget->listToolbarSearch->getActiveTerm();
       if (strlen($searchTerm)) {
           $records = $records->merge(YourModel::transWhere('name', $searchTerm, 'fr')->get());
       }
       return $records;
   }

Be aware that this trick does not return paginated results.

Credits to andreas on Slack.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?