Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example query generator. Fixed bug where iDisplayStart was 0 th…
…at resulted in LIMIT not being set.
- Loading branch information
Jim Pravetz
committed
Oct 8, 2012
1 parent
66b0b7e
commit 26f1f89
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* generate | ||
* https://github.com/jpravetz/node-datatable | ||
* Copyright(c) 2012 Jim Pravetz <jpravetz@epdoc.com> | ||
* node-datatable may be freely distributed under the MIT license. | ||
*/ | ||
|
||
var QueryBuilder = require('../index.js'); | ||
|
||
var oTableDef = { | ||
sTableName: "Orgs", | ||
aoColumnDefs: [ | ||
{ mData: "o", bSearchable: true }, | ||
{ mData: "cn", bSearchable: true }, | ||
{ mData: "support" }, | ||
{ mData: "email" } | ||
] | ||
}; | ||
|
||
var oDatatableParams = { | ||
iDisplayStart: 0, | ||
iDisplayLength: 4, | ||
"sSearch": "", | ||
"bRegex": "false", | ||
"sSearch_0": "", | ||
"bRegex_0": "false", | ||
"bSearchable_0": "true", | ||
"sSearch_1": "", | ||
"bRegex_1": "false", | ||
"bSearchable_1": "true", | ||
"sSearch_2": "", | ||
"bRegex_2": "false", | ||
"bSearchable_2": "true", | ||
"sSearch_3": "", | ||
"bRegex_3": "false", | ||
"bSearchable_3": "true", | ||
"iSortCol_0": "0", | ||
"sSortDir_0": "asc", | ||
"iSortingCols": "1", | ||
"bSortable_0": "true", | ||
"bSortable_1": "true", | ||
"bSortable_2": "true", | ||
"bSortable_3": "true" | ||
}; | ||
|
||
generate( oTableDef, oDatatableParams ); | ||
oDatatableParams.sSearch = 'hello'; | ||
generate( oTableDef, oDatatableParams ); | ||
oDatatableParams.iSortCol_0 = 2; | ||
oDatatableParams.sSortDir_0 = 'desc'; | ||
generate( oTableDef, oDatatableParams ); | ||
oDatatableParams.iDisplayStart = 30; | ||
oDatatableParams.iDisplayLength = 15; | ||
generate( oTableDef, oDatatableParams ); | ||
|
||
function generate( oTableDef, oDatatableParams ) { | ||
var queryBuilder = new QueryBuilder( oTableDef ); | ||
var queries = queryBuilder.buildQuery( oDatatableParams ); | ||
console.log( "Queries:\n %s", queries.join("\n ") ); | ||
} |