sails-datatable

0.10.5 • Public • Published

image_squidhome@2x.png

sails-datatable

This module is a Waterline/Sails adapter to use with jQuery datatable (tested on 1.10.4). I implement only basic things.

Installation

To install this adapter, run:

$ npm install sails-datatable

Usage

This adapter exposes the following methods:

datatable(params)
  • params variable is datatable params

Example of use

After you install follow these steps:

1.Open config/adapters.js and put there:

'sails-datatable': require('sails-datatable');

2.Open config/connections.js and add:

    datatable: {
        adapter: 'sails-datatable'
    },

3.Open model file and add connection:

connection: 'datatable',

4.In controller add datatable action (example below):

datatable: {
    action: function (req, res, next) {
        Model.datatable(req.body, function (err, data) {
            if (err) {
                return next(new error.InvalidContentError(err));
            } else {
                res.send(data);
                next();
            }
        });
    }
}

5.Populate in datatable:

datatable: {
    action: function (req, res, next) {
        req.params.populate = ['item1', 'item2', 'item3'];
 
        Model.datatable(req.body, function (err, data) {
            if (err) {
                return next(new error.InvalidContentError(err));
            } else {
                res.send(data);
                next();
            }
        });
    }
}

6.Filter in datatable:

datatable: {
    action: function (req, res, next) {
        // Like where conditions in waterline
        req.params.filter = {
            param1: 'value1'
        };
 
        Model.datatable(req.body, function (err, data) {
            if (err) {
                return next(new error.InvalidContentError(err));
            } else {
                res.send(data);
                next();
            }
        });
    }
}

License

MIT © 2014 lukaszpaczos

Sails is free and open-source under the MIT License.

githalytics.com alpha

Package Sidebar

Install

npm i sails-datatable

Weekly Downloads

1

Version

0.10.5

License

MIT

Last publish

Collaborators

  • lukaszpaczos