jQuery::DataTables - серверная часть для выполнения AJAX запросов DataTables
use strict; use jQuery::DataTables;
... my $dt = new jQuery::DataTables( cgi => $cgi, dbh => $c->app->dbh ); my $res = $dt->getTableData( 'SELECT DISTINCT id, col_int, col_text, col_real FROM datatable', [qw{id col_int col_text col_real}] ); $c->render( json => $res );
Подготавливает данные из DataTable запроса для удобного использования и возвращает хэш с данными. Делается это для упрощения использования странного формата, заложенного в DataTables изначально.
Type Name Info -------------------- int iDisplayStart Display start point in the current data set. $iDisplayStart int iDisplayLength Number of records that the table can display in the current draw. $iDisplayLength It is expected that the number of records returned will be equal to this number, unless the server has fewer records to return. int iColumns Number of columns being displayed (useful for getting individual column search info) $iColumns string sSearch Global search field $sSearch bool bRegex True if the global filter should be treated as a regular expression for advanced filtering, false if not. $bRegex bool bSearchable_(int) Indicator for if a column is flagged as searchable or not on the client-side @abSearchable string sSearch_(int) Individual column filter @asSearch bool bRegex_(int) True if the individual column filter should be treated as a regular expression @abRegex for advanced filtering, false if not bool bSortable_(int) Indicator for if a column is flagged as sortable or not on the client-side @abSortable int iSortingCols Number of columns to sort on $iSortingCols int iSortCol_(int) Column being sorted on (you will need to decode this number for your database) @aiSortCol string sSortDir_(int) Direction to be sorted - "desc" or "asc". @asSortDir string mDataProp_(int) The value specified by mDataProp for each column. This can be useful @amDataProp for ensuring that the processing of data is independent from the order of the columns. string sEcho Information for DataTables to use for rendering. $sEcho
Мы можем вызывать эту функцию с указанием запроса и какие столбцы он возвращает, например
getTableData ('SELECT a,b,c FROM table', ['a', 'b', 'c'])
Названия столбцов в фильтрах будут использоваться с указанием их в кавычках, так что надо указывать имена столбцов так, чтобы база данных их правильно поняла. Многие СУБД позволяют имена столюцов возвращать большими или маленькими буквами, по флагу FetchHashKeyName => 'NAME_lc' или FetchHashKeyName => 'NAME_uc'.
К этому запросу добавляется поисковое выражение WHERE, сортировка ORDER BY и лимиты LIMIT ... OFFSET
Поисковое выражение может быть одно на все столбцы, либо разные выражения на разные (некоторые!) столбцы.
Поисковое выражение должно трактоваться как regexp либо для всех столбцов, либо regexp для некоторых столбцов.
Сначала выполняется общее поисковое выражение (если указано), затем для полученного результата выполняются индивидуальные для столбцов поисковые выражения. Ясно, что лучше использовать только индивидуальные выражения.
Данная реализация не учитывает флаг bRegex - так как пока непонятно, как обеспечить исполнение этого флага для разных СУБД.
Konstantin Tokar <konstantin@tokar.ru>
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'серверная'. Assuming UTF-8
To install jQuery::DataTables, copy and paste the appropriate command in to your terminal.
cpanm
cpanm jQuery::DataTables
CPAN shell
perl -MCPAN -e shell install jQuery::DataTables
For more information on module installation, please visit the detailed CPAN module installation guide.