npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sails-datatables

v1.2.0

Published

This is a sailsjs library that helps you integrate datatables (Javascript datatables) with your sails app.

Downloads

8

Readme

sails-datatables

This is a sailsjs library that helps you integrate datatables (Javascript datatables) with your sails app.

Get Started

This library would help you easily query your sails endpoint for datasets that is easily understood by javascript datatables. It works like blueprint, so you can imagine how easy it must be to use. Try and testify!!!

Installation

With node installed:

npm install sails-datatables --save

Endpoint

Just like blueprint actions a datatable action is automatically available on all models for you.

//assuming you have a model User
/user/datatable

//or if you have a prefix api
/api/user/datatable

Policies

The datatable action automatically inherits its parent policies.

//in config/policies.js
module.exports.policies = {
    // all datatable route inherit this by default.
    '*': [
        'hasToken',
        'isAuthenticated',
        'ModelPolicy',
        'PermissionPolicy',
        'RolePolicy'
    ],
    
    // user/datatable route would not be bound by any policy
    UserController: [],
    
    // rabbit/datatable route would only inherit these two policies
    RabbitController: [
        'hasToken',
        'isAuthenticated'
    ],
    
    // payment/datatable route would only inherit this one policy
    PaymentController: {
        'datatable':[
          'isAuthenticated'
        ]
    }
}

Usage

Send a GET or POST to /model/datatable or /api/model/datatable if you have the api prefix turned on in blueprint. Please rely on Datatable's Documentation for your implementation on the frontend.

        vm.dtOptions = {
            ...
            processing: true,
            serverSide: true,
            ajax: {
                //the url to the model/datatable
                url: 'http://#######/model/datatable',
                //You can use either a GET or POST verb
                type: 'GET',
                dataSrc: "aaData"
            },
            ...
        }

Nested data are automatically populated for you using the dot notations in your datatable options column definition

NB: Sails can only populate nested data two levels deep.
        vm.dtOptions = {
            ...
            aoColumns: [
                {
                    mData: "trackingNumber"
                },
                {
                    mData: "address.city"
                },
                {
                    mData: "status"
                },
                {
                    mData: "createdAt",
                    bSortable: true,
                    mRender: function (data, type, row, meta) {
                        return helper.getHumanReadableDate(row.createdAt);
                    }
                }
            ],
            ...
        }

Advanced

You can add some extra data to your request to perform advanced functions like filter or range on a particular query. Cool rite :-)?

        {
            //filter only records that have a color of yellow
            data: "color",
            searchable:  true,
            search: {
                value: "yellow"
            }
        };

or

        {
            data: "createdAt",
            //Just make searchable true in your case, 
            //I only wanted to make sure the dates were good 
            //for the server before sending
            searchable: moment(vm.range.fromDate).isValid() && moment(vm.range.toDate).isValid(),
            search: {
                value: {
                    //Make sure you send dates in a format sails understand
                    //This method also works for integers and strings.
                    //Can be used to get data whose values fall within a range
                    from: helper.getISOServerReadableDate(vm.range.fromDate),
                    to: helper.getISOServerReadableDate(vm.range.toDate)
                }
            }
        }

Feature Requests

If you have an idea for a new feature, please feel free to submit it as a pull request to this repository.

Contributing

  1. Fork it gently!
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Some commit message'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request :D
  6. Your name shows up in credits

Credits

License

MIT License Copyright © 2016