-
Notifications
You must be signed in to change notification settings - Fork 4
Pagination Configuration
Branden Horiuchi edited this page Nov 6, 2015
·
10 revisions
bookshelf-pagemaker
allows you to completely customize your pagination output, pagination configurations are customizable.
A custom pagination configuration can be passed as the second argument to the main bookshelf-pagemaker
function. Alternately one of the supported paginations (paged
, offset
, or datatables
) can be specified using the name as a string
// define a custom pagination configuration
var custom = {
...
};
pm(MyModel, custom).forge()
.paginate()
.end()
.then(function(page) {
// code to display the page
});
-
usePages
Boolean
- determines if pages or limit/offset will be used -
input
Object
- Hash of input configurations. These configurations determine how received data is processed-
search
Object
- Hash containing search configuration -
order
Object
- Hash containing order configuration -
columns
Object
- Hash containing column configuration
-
-
fields
Object
- Hash containing pagination output field configurations-
start
Object
- Hash containing start output configuration -
length
Object
- Hash containing length output configuration -
recordsTotal
Object
- Hash containing recordsTotal output configuration -
recordsFiltered
Object
- Hash containing recordsFiltered output configuration -
data
Object
- Hash containing data output configuration -
error
Object
- Hash containing error output configuration -
pagesTotal
Object
- Hash containing pagesTotal output configuration -
pagesFiltered
Object
- Hash containing recordsTotal output configuration -
currentPage
Object
- Hash containing currentPage output configuration -
previous
Object
- Hash containing previous output configuration -
next
Object
- Hash containing next output configuration
-
-
rows
Object
- Hash containing optional row output configuration. Each row will have fields added. This is mainly fordatatables
-
transforms
Object[]
- Optional array of input values to transform and display
{
usePages:true,
input:{
search:{
param:'search',
fields:{
value:'value',
regex:'regex'
}
},
order:{
param:'order',
defaultDirection:'asc',
fields:{
column:'column',
direction:'dir'
}
},
columns:{
param:'columns',
fields:{
data:'data',
name:'name',
searchable:'searchable',
orderable:'orderable'
}
}
},
fields:{
start:{
show:false,
displayName:'start',
param:'start',
defaultValue:0
},
length:{
show:true,
displayName:'limit',
param:'limit',
defaultValue:10,
maximum:50,
displayOrder:3
},
recordsTotal:{
show:false,
displayName:'recordsTotal'
},
recordsFiltered:{
show:false,
displayName:'recordsFiltered'
},
data:{
show:true,
displayName:'resources',
displayOrder:6
},
error:{
show:false,
displayName:'error'
},
pagesTotal:{
show:true,
displayName:'pagesTotal',
displayOrder:4
},
pagesFiltered:{
show:true,
displayName:'pagesFiltered',
displayOrder:5
},
currentPage:{
show:true,
displayName:'current',
param:'page',
defaultValue:1,
displayOrder:1
},
previous:{
show:true,
displayName:'previous',
displayOrder:0
},
next:{
show:true,
displayName:'next',
displayOrder:2
}
}
}
{
usePages:false,
input:{
search:{
param:'search',
fields:{
value:'value',
regex:'regex'
}
},
order:{
param:'order',
defaultDirection:'asc',
fields:{
column:'column',
direction:'dir'
}
},
columns:{
param:'columns',
fields:{
data:'data',
name:'name',
searchable:'searchable',
orderable:'orderable'
}
}
},
fields:{
start:{
show:false,
displayName:'start',
param:'start',
defaultValue:0
},
length:{
show:false,
displayName:'length',
param:'length',
defaultValue:10,
maximum:50
},
recordsTotal:{
show:true,
displayName:'recordsTotal',
displayOrder:1
},
recordsFiltered:{
show:true,
displayName:'recordsFiltered',
displayOrder:2
},
data:{
show:true,
displayName:'data',
displayOrder:3
},
error:{
show:true,
displayName:'error'
},
pagesTotal:{
show:false,
displayName:'pagesTotal'
},
pagesFiltered:{
show:false,
displayName:'pagesFiltered'
},
currentPage:{
show:false,
displayName:'currentPage',
param:'page',
defaultValue:1
},
previous:{
show:false,
displayName:'previous'
},
next:{
show:false,
displayName:'next'
}
},
rows:{
rowId:{
show:true,
displayName:'DT_RowId',
get:function(model, record) {
if (model.idAttribute && record.hasOwnProperty(model.idAttribute)) {
return record[model.idAttribute];
}
return null;
}
},
rowClass:{
show:true,
displayName:'DT_RowClass',
get:function(model, record) {
if (typeof (model._rowClass) === 'function') {
return model._rowClass(model, record);
}
return null;
}
},
rowData:{
show:true,
displayName:'DT_RowData',
get:function(model, record) {
if (typeof (model._rowData) === 'function') {
return model._rowData(model, record);
}
return null;
}
},
rowAttr:{
show:true,
displayName:'DT_RowAttr',
get:function(model, record) {
if (typeof (model._rowAttr) === 'function') {
return model._rowAttr(model, record);
}
return null;
}
}
},
transforms:[
{
displayName:'draw',
displayOrder:0,
param:'draw',
transform:function(value) {
return !isNaN(value) ? parseInt(value, 10) : 1;
}
}
],
}