Skip to content

Pagination Configuration

Branden Horiuchi edited this page Nov 6, 2015 · 10 revisions

Pagination Configuration


bookshelf-pagemaker allows you to completely customize your pagination output, pagination configurations are customizable.


Usage

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
});

Format

  • 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
      • param String - Query string parameter name to look for
      • fields Object - Hash containing search field configuration
        • value String - Query string parameter for the search value
        • regex String - Query string parameter for the regex value
    • order Object - Hash containing order configuration
      • param String - Query string parameter name to look for
      • defaultDirection String - Direction to default order to (asc or desc)
      • fields Object - Hash containing search field configuration
        • column String - Query string parameter for the column name
        • direction String - Query string parameter for the search direction
    • columns Object - Hash containing column configuration
      • param String - Query string parameter name to look for
      • fields Object - Hash containing search field configuration
        • data String - Query string parameter for the column data
        • name String - Query string parameter for the column name
        • searchable String - Query string parameter for the searchable name
        • orderable String - Query string parameter for the orderable name
  • fields Object - Hash containing pagination output field configurations
    • start Object - Hash containing start output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • param String - Query string parameter for offset
      • defaultValue Number - Default value to use
      • displayOrder Number - Order to show the field
    • length Object - Hash containing length output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • param String - Query string parameter for page size
      • defaultValue Number - Default value to use
      • maximum Number - Maximum allowed records per page
      • displayOrder Number - Order to show the field
    • recordsTotal Object - Hash containing recordsTotal output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • recordsFiltered Object - Hash containing recordsFiltered output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • data Object - Hash containing data output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • error Object - Hash containing error output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
    • pagesTotal Object - Hash containing pagesTotal output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • pagesFiltered Object - Hash containing recordsTotal output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • currentPage Object - Hash containing currentPage output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
      • param String - Query string parameter for page
      • defaultValue Number - Default value to use
    • previous Object - Hash containing previous output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
    • next Object - Hash containing next output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • displayOrder Number - Order to show the field
  • rows Object - Hash containing optional row output configuration. Each row will have fields added. This is mainly for datatables
    • rowId Object - Hash containing rowId output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • get Function - Function that takes the model and current record as its inputs and returns a value to use as output
    • rowClass Object - Hash containing rowClass output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • get Function - Function that takes the model and current record as its inputs and returns a value to use as output
    • rowData Object - Hash containing rowData output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • get Function - Function that takes the model and current record as its inputs and returns a value to use as output
    • rowAttr Object - Hash containing rowAttr output configuration
      • show Boolean - determines if the field will be shown
      • displayName String - Name used to display the field
      • get Function - Function that takes the model and current record as its inputs and returns a value to use as output
  • transforms Object[] - Optional array of input values to transform and display
    • displayName String - Name used to display the field
    • displayOrder Number - Order to show the field
    • param String - Query string parameter for the transform
    • transform Function - Function that takes the input value as its inputs and returns a value to use as output

Default Paged example

{
  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
    }
  }
}

Datatables example

{
  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;
      }
    }
  ],
}
Clone this wiki locally