KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

DataTable Server Side with Filter #1938

Open Daniel opened this topic on on Mar 2, 2021 - 2 comments

Daniel commented on Mar 2, 2021

Hi, I noticed that filter function doesn't work when applied to serverside datatable. It works well when serverside is turned off or applied to other charts. Here's the code:

$dataSource = function() {
            return $this->src($this->params['database'])
            ->query($this->params['query_input'])
             ->pipeIf(!empty($this->params['filters']), function($node) {
                $filters = $this->params['filters'];
                $convertedFilters = [];
                for ($i = 0; $i < sizeof($filters['filter_field']); $i++) { 
                    $convertedFilters[] = [$filters['filter_field'][$i], $filters['filter_operator'][$i], $filters['filter_value'][$i]];
                }
                return $node->pipe(new Filter($convertedFilters));
            })
};
David Winterburn commented on Mar 3, 2021

Hi Daniel,

With DataTables' server side processing, it can not know which outside parameters to send to the server. Thus, we have to explicit set the parameters ourselves via the "scope" property like this:

    DataTables::create(array(
                    'name' => 'salesTable0',
                    'scope' => $this->params,    
                    'dataSource' => function($scope) {
                        //Use $scope like $this->params here
                        ....        

Please try it and let us know if it works for you. Thanks!

Daniel commented on Mar 5, 2021

Still doesn't work.

$dataSource = function($scope) {
            return $this->src($scope['database'])
            ->query($scope['query_input'])
            ->pipeIf(!empty($scope['filter']), function($node) {
              $filters = $scope['filters'];
              $convertedFilters = [];
              for ($i = 0; $i < sizeof($filters['filter_field']); $i++) { 
                  $convertedFilters[] = [$filters['filter_field'][$i], $filters['filter_operator'][$i], $filters['filter_value'][$i]];
              }
              return $node->pipe(new Filter($convertedFilters));
            });
          };

Datatables::create([
          'name' => 'uniqueTable',
          'Title' => $this->params['title'],
          'scope' => $this->params,
          'dataSource' => $dataSource,
          'columns' => $columns,
          'options' => 
          [
            'searching' => $searching, 
            'colReorder' => true, 
            'paging' => $paging
          ],
          'serverSide' => $serverSide,
          'cssClass' => $cssClass
        ]);

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
bug

DataGrid