{"id":14975656,"url":"https://github.com/archr/mongoose-datatables","last_synced_at":"2025-07-22T09:33:29.572Z","repository":{"id":25683331,"uuid":"29119308","full_name":"archr/mongoose-datatables","owner":"archr","description":"Server side dataTable request.","archived":false,"fork":false,"pushed_at":"2021-04-19T14:09:39.000Z","size":477,"stargazers_count":23,"open_issues_count":11,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-25T11:56:07.258Z","etag":null,"topics":["datatables","mongoose-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-12T04:53:10.000Z","updated_at":"2023-04-24T19:22:02.000Z","dependencies_parsed_at":"2022-09-15T07:22:31.467Z","dependency_job_id":null,"html_url":"https://github.com/archr/mongoose-datatables","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/archr/mongoose-datatables","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archr%2Fmongoose-datatables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archr%2Fmongoose-datatables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archr%2Fmongoose-datatables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archr%2Fmongoose-datatables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archr","download_url":"https://codeload.github.com/archr/mongoose-datatables/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archr%2Fmongoose-datatables/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266465379,"owners_count":23933118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datatables","mongoose-plugin"],"created_at":"2024-09-24T13:52:20.873Z","updated_at":"2025-07-22T09:33:29.528Z","avatar_url":"https://github.com/archr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-datatables\n\nServer side table request.\n\n[![Build Status](https://travis-ci.org/archr/mongoose-datatables.svg)](https://travis-ci.org/archr/mongoose-datatables)\n\n## Installation\n```sh\n$ npm install mongoose-datatables\n```\n\n## Usage\nConfigure the plugin in your model\n\n```javascript\nvar mongoose = require('mongoose')\nvar dataTables = require('mongoose-datatables')\nvar Schema = mongoose.Schema\n\nvar UserSchema = new Schema({\n  first_name: String,\n  last_name: String,\n  username: String\n})\n\nUserSchema.plugin(dataTables)\n```\nUse plugin in your route\n\n```javascript\napp.post('/table', (req, res) {\n  User.dataTables({\n    limit: req.body.length,\n    skip: req.body.start,\n    search: {\n      value: req.body.search.value,\n      fields: ['username']\n    },\n    sort: {\n      username: 1\n    }\n  }).then(function (table) {\n    res.json(table); // table.total, table.data\n  })\n});\n```\n\n## API\n\n### plugin([options])\n* `options.totalKey` (String) - Default total\n* `options.dataKey` (String) - Default data\n* `options.formatters` (Object) - Specifies multiple formatters that can be used in the query\n\n### dataTables([options], [callback])\n* `options.limit` (Number) - Specifies mongo limit.\n* `options.skip` (Number) - Specifies mongo skip.\n* `options.find` (Object) - Specifies selection criteria.\n* `options.select` (Object) - Specifies the fields to return.\n* `options.sort` (Object) - Specifies the order in which the query returns matching documents.\n* `options.order`, `options.columns` (Array), (Array) - Specifies the order in which the query returns matching documents and replace the sort option\n* `options.search` (Object) - Search.\n* `options.populate` (Object) - Specifies models to populate.\n* `options.formatter` (String|Function) - Specifies formatter to use after the query.\n\n\n### Formaters\n\nAt query level\n```javascript\nUser.dataTables({\n  limit: 20,\n  formatter: function(user) {\n    return {\n      name: user.first_name + ' ' + user.last_name\n    }\n  }\n})\n```\n\nAt schema level\n```javascript\nUserSchema.plugin(dataTables, {\n  formatters: {\n    toPublic : function (user) {\n      return {\n        name: user.first_name + ' ' + user.last_name\n      }\n    }\n  }\n});\n```\n\nUse by doing this at query level\n```javascript\nUser.dataTables({\n  limit: 20,\n  formatter: 'toPublic',\n})\n```\n**Note:** if you use formatters you get an array of objects on data, instead of the model instance.\n\n\n## License\nMIT \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchr%2Fmongoose-datatables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchr%2Fmongoose-datatables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchr%2Fmongoose-datatables/lists"}