コード例 #1
0
ファイル: DataTable.php プロジェクト: mzf/phalcon-datatables
 public function fromBuilder($builder, $columns = [])
 {
     if (empty($columns)) {
         $columns = $builder->getColumns();
         $columns = is_array($columns) ? $columns : array_map('trim', explode(',', $columns));
     }
     $adapter = new QueryBuilder($this->options['length']);
     $adapter->setBuilder($builder);
     $adapter->setParser($this->parser);
     $adapter->setColumns($columns);
     $this->response = $adapter->getResponse();
     return $this;
 }
コード例 #2
0
            $carry[] = $item['name'];
            return $carry;
        });
        expect($names)->toBe(['gebert', 'marvin.maybelle', 'zabernathy']);
    });
    it("should order", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'desc']]];
        $dataTables = new QueryBuilder(20);
        $dataTables->setBuilder($this->builder);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('zcremin');
    });
    it("should order asc", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'asc']]];
        $dataTables = new QueryBuilder(20);
        $dataTables->setBuilder($this->builder);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('adelia13');
    });
    afterEach(function () {
        unset($_GET);
        unset($_POST);
        unset($_REQUEST);
    });
});