Example #1
0
 /**
  * Applies filtering to data source.
  */
 public function apply()
 {
     $value = $this->getValue();
     if (null === $value || '' === $value) {
         return;
     }
     if ($func = $this->config->getFilteringFunc()) {
         $func($value, $this->grid->getConfig()->getDataProvider());
         return;
     }
     $operator = $this->config->getOperator();
     if ($operator === FilterConfig::OPERATOR_LIKE || $operator === FilterConfig::OPERATOR_LIKE_R) {
         // Search for non-escaped wildcards
         $found = false;
         for ($i = 0; $i < mb_strlen($value); $i++) {
             if (in_array(mb_substr($value, $i, 1), ['%', '_']) && $i > 0 && mb_substr($value, $i - 1, 1) != '\\') {
                 $found = true;
                 break;
             }
         }
         // If none are found, insert wildcards to improve user experience
         if (!$found) {
             if ($operator === FilterConfig::OPERATOR_LIKE) {
                 $value = "%{$value}%";
             } else {
                 if ($operator === FilterConfig::OPERATOR_LIKE_R) {
                     $value .= '%';
                 }
             }
         }
     }
     $this->grid->getConfig()->getDataProvider()->filter($this->config->getName(), $this->config->getOperator(), $value);
 }
Example #2
0
 /**
  * Applies filtering to data source.
  */
 public function apply()
 {
     $value = $this->getValue();
     if (null === $value || '' === $value) {
         return;
     }
     if ($func = $this->config->getFilteringFunc()) {
         $func($value, $this->grid->getConfig()->getDataProvider());
         return;
     }
     $isLike = $this->config->getOperator() === FilterConfig::OPERATOR_LIKE;
     if ($isLike && strpos($value, '%') === false) {
         $value = "%{$value}%";
     }
     $this->grid->getConfig()->getDataProvider()->filter($this->config->getName(), $this->config->getOperator(), $value);
 }
Example #3
0
 public function renderFilter(FilterConfig $filter)
 {
     $data = $this->getViewData();
     $data['column'] = $filter->getAttachedColumn();
     $data['filter'] = $filter;
     return View::make($this->getFilterTemplate($filter), $data);
 }