datatables.net-feature-deeplink 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
# DataTables deep linking
|
|
3
|
+
|
|
4
|
+
This feature plug-in for DataTables provides a function which will take DataTables options from the browser's URL search string and return an object that can be used to construct a DataTable.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
To install with npm (substitute with your favorite package manager if you prefer):
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install datatables.net datatables.net-feature-deeplink
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then in your Javascript file (assuming you are using ES Modules):
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import DataTable from 'datatables.net';
|
|
19
|
+
import 'datatables.net-feature-deeplink';
|
|
20
|
+
|
|
21
|
+
new DataTable(
|
|
22
|
+
'#example',
|
|
23
|
+
DataTable.deepLink(['pageLength', 'search.search'])
|
|
24
|
+
);
|
|
25
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*! © SpryMedia Ltd - datatables.net/license */
|
|
2
|
+
/**
|
|
3
|
+
* @summary LengthLinks
|
|
4
|
+
* @description Deep linking options parsing support for DataTables
|
|
5
|
+
* @file dataTables.deepLink.js
|
|
6
|
+
* @author SpryMedia Ltd
|
|
7
|
+
* @copyright Copyright SpryMedia Ltd.
|
|
8
|
+
* @license MIT - http://datatables.net/license/mit
|
|
9
|
+
*
|
|
10
|
+
* This feature plug-in for DataTables provides a function which will
|
|
11
|
+
* take DataTables options from the browser's URL search string and
|
|
12
|
+
* return an object that can be used to construct a DataTable. This
|
|
13
|
+
* allows deep linking to be easily implemented with DataTables - for
|
|
14
|
+
* example a URL might be `myTable?displayStart=10` which will
|
|
15
|
+
* automatically cause the second page of the DataTable to be displayed.
|
|
16
|
+
*
|
|
17
|
+
* This plug-in works on a whitelist basis - you must specify which
|
|
18
|
+
* [initialisation parameters](//datatables.net/reference/option) you
|
|
19
|
+
* want the URL search string to specify. Any parameter given in the
|
|
20
|
+
* URL which is not listed will be ignored (e.g. you are unlikely to
|
|
21
|
+
* want to let the URL search string specify the `ajax` option).
|
|
22
|
+
*
|
|
23
|
+
* This specification is done by passing an array of property names
|
|
24
|
+
* to the `DataTable.deepLink` function. If you do which to
|
|
25
|
+
* allow _every_ parameter (I wouldn't recommend it) you can use `all`
|
|
26
|
+
* instead of an array.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Allow a display start point and search string to be specified
|
|
30
|
+
* new DataTable(
|
|
31
|
+
* '#example',
|
|
32
|
+
* DataTable.deepLink(['pageLength', 'search.search'])
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // As above, but with a default search
|
|
37
|
+
* var options = DataTable.deepLink(['displayStart', 'search.search']);
|
|
38
|
+
*
|
|
39
|
+
* new DataTable(
|
|
40
|
+
* '#myTable',
|
|
41
|
+
* DataTable.util.object.assignDeep({
|
|
42
|
+
* search: { search: 'Initial search value' }
|
|
43
|
+
* }, options)
|
|
44
|
+
* );
|
|
45
|
+
*/
|
|
46
|
+
import { Options } from 'datatables.net';
|
|
47
|
+
declare module 'datatables.net' {
|
|
48
|
+
interface DataTablesStatic {
|
|
49
|
+
/** Deep linking options parsing support for DataTables */
|
|
50
|
+
deepLink(whitelist: 'all' | string[]): Options;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
|
|
2
|
+
|
|
3
|
+
(function(factory){
|
|
4
|
+
if (typeof define === 'function' && define.amd) {
|
|
5
|
+
// AMD
|
|
6
|
+
define(['datatables.net'], function (dt) {
|
|
7
|
+
return factory(window, document, dt);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
else if (typeof exports === 'object') {
|
|
11
|
+
// CommonJS
|
|
12
|
+
var cjsRequires = function (root) {
|
|
13
|
+
if (! root.DataTable) {
|
|
14
|
+
require('datatables.net')(root);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
module.exports = function (root) {
|
|
20
|
+
if (! root) {
|
|
21
|
+
// CommonJS environments without a window global must pass a
|
|
22
|
+
// root. This will give an error otherwise
|
|
23
|
+
root = window;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
cjsRequires(root);
|
|
27
|
+
return factory(root, root.document, root.DataTable);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
cjsRequires(window);
|
|
32
|
+
module.exports = factory(window, window.document, window.DataTable);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Browser
|
|
37
|
+
factory(window, document, window.DataTable);
|
|
38
|
+
}
|
|
39
|
+
}(function(window, document, DataTable) {
|
|
40
|
+
'use strict';
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @summary LengthLinks
|
|
45
|
+
* @description Deep linking options parsing support for DataTables
|
|
46
|
+
* @file dataTables.deepLink.js
|
|
47
|
+
* @author SpryMedia Ltd
|
|
48
|
+
* @copyright Copyright SpryMedia Ltd.
|
|
49
|
+
* @license MIT - http://datatables.net/license/mit
|
|
50
|
+
*
|
|
51
|
+
* This feature plug-in for DataTables provides a function which will
|
|
52
|
+
* take DataTables options from the browser's URL search string and
|
|
53
|
+
* return an object that can be used to construct a DataTable. This
|
|
54
|
+
* allows deep linking to be easily implemented with DataTables - for
|
|
55
|
+
* example a URL might be `myTable?displayStart=10` which will
|
|
56
|
+
* automatically cause the second page of the DataTable to be displayed.
|
|
57
|
+
*
|
|
58
|
+
* This plug-in works on a whitelist basis - you must specify which
|
|
59
|
+
* [initialisation parameters](//datatables.net/reference/option) you
|
|
60
|
+
* want the URL search string to specify. Any parameter given in the
|
|
61
|
+
* URL which is not listed will be ignored (e.g. you are unlikely to
|
|
62
|
+
* want to let the URL search string specify the `ajax` option).
|
|
63
|
+
*
|
|
64
|
+
* This specification is done by passing an array of property names
|
|
65
|
+
* to the `DataTable.deepLink` function. If you do which to
|
|
66
|
+
* allow _every_ parameter (I wouldn't recommend it) you can use `all`
|
|
67
|
+
* instead of an array.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Allow a display start point and search string to be specified
|
|
71
|
+
* new DataTable(
|
|
72
|
+
* '#example',
|
|
73
|
+
* DataTable.deepLink(['pageLength', 'search.search'])
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // As above, but with a default search
|
|
78
|
+
* var options = DataTable.deepLink(['displayStart', 'search.search']);
|
|
79
|
+
*
|
|
80
|
+
* new DataTable(
|
|
81
|
+
* '#myTable',
|
|
82
|
+
* DataTable.util.object.assignDeep({
|
|
83
|
+
* search: { search: 'Initial search value' }
|
|
84
|
+
* }, options)
|
|
85
|
+
* );
|
|
86
|
+
*/
|
|
87
|
+
DataTable.deepLink = function (whitelist) {
|
|
88
|
+
var search = location.search.replace(/^\?/, '').split('&');
|
|
89
|
+
var out = {};
|
|
90
|
+
for (var i = 0, ien = search.length; i < ien; i++) {
|
|
91
|
+
var pair = search[i].split('=');
|
|
92
|
+
var key = decodeURIComponent(pair[0]);
|
|
93
|
+
var value = decodeURIComponent(pair[1]);
|
|
94
|
+
// "Casting"
|
|
95
|
+
if (value === 'true') {
|
|
96
|
+
value = true;
|
|
97
|
+
}
|
|
98
|
+
else if (value === 'false') {
|
|
99
|
+
value = false;
|
|
100
|
+
}
|
|
101
|
+
else if (!value.match(/[^\d]/) && key !== 'search.search') {
|
|
102
|
+
// don't convert if searching or it'll break the search
|
|
103
|
+
value = value * 1;
|
|
104
|
+
}
|
|
105
|
+
else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
|
|
106
|
+
// Try to JSON parse for arrays and objects
|
|
107
|
+
try {
|
|
108
|
+
value = JSON.parse(value);
|
|
109
|
+
}
|
|
110
|
+
catch (e) { }
|
|
111
|
+
}
|
|
112
|
+
if (whitelist === 'all' || whitelist.indexOf(key) !== -1) {
|
|
113
|
+
var setter = DataTable.util.set(key);
|
|
114
|
+
setter(out, value, {});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
return DataTable;
|
|
122
|
+
}));
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
|
|
2
|
+
(n=>{var t;"function"==typeof define&&define.amd?define(["datatables.net"],function(e){return n(window,document,e)}):"object"==typeof exports?(t=function(e){e.DataTable||require("datatables.net")(e)},"undefined"==typeof window?module.exports=function(e){return e=e||window,t(e),n(0,e.document,e.DataTable)}:(t(window),module.exports=n(window,window.document,window.DataTable))):n(window,document,window.DataTable)})(function(e,n,r){return r.deepLink=function(e){for(var n=location.search.replace(/^\?/,"").split("&"),t={},o=0,a=n.length;o<a;o++){var d=n[o].split("="),i=decodeURIComponent(d[0]),d=decodeURIComponent(d[1]);if("true"===d)d=!0;else if("false"===d)d=!1;else if(d.match(/[^\d]/)||"search.search"===i){if(0===d.indexOf("{")||0===d.indexOf("["))try{d=JSON.parse(d)}catch(e){}}else d=+d;"all"!==e&&-1===e.indexOf(i)||r.util.set(i)(t,d,{})}return t},r});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
|
|
2
|
+
import DataTable from"datatables.net";DataTable.deepLink=function(e){for(var a=location.search.replace(/^\?/,"").split("&"),t={},l=0,r=a.length;l<r;l++){var i=a[l].split("="),n=decodeURIComponent(i[0]),i=decodeURIComponent(i[1]);if("true"===i)i=!0;else if("false"===i)i=!1;else if(i.match(/[^\d]/)||"search.search"===n){if(0===i.indexOf("{")||0===i.indexOf("["))try{i=JSON.parse(i)}catch(e){}}else i=+i;"all"!==e&&-1===e.indexOf(n)||DataTable.util.set(n)(t,i,{})}return t};export default DataTable;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
|
|
2
|
+
|
|
3
|
+
import DataTable from 'datatables.net';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @summary LengthLinks
|
|
7
|
+
* @description Deep linking options parsing support for DataTables
|
|
8
|
+
* @file dataTables.deepLink.js
|
|
9
|
+
* @author SpryMedia Ltd
|
|
10
|
+
* @copyright Copyright SpryMedia Ltd.
|
|
11
|
+
* @license MIT - http://datatables.net/license/mit
|
|
12
|
+
*
|
|
13
|
+
* This feature plug-in for DataTables provides a function which will
|
|
14
|
+
* take DataTables options from the browser's URL search string and
|
|
15
|
+
* return an object that can be used to construct a DataTable. This
|
|
16
|
+
* allows deep linking to be easily implemented with DataTables - for
|
|
17
|
+
* example a URL might be `myTable?displayStart=10` which will
|
|
18
|
+
* automatically cause the second page of the DataTable to be displayed.
|
|
19
|
+
*
|
|
20
|
+
* This plug-in works on a whitelist basis - you must specify which
|
|
21
|
+
* [initialisation parameters](//datatables.net/reference/option) you
|
|
22
|
+
* want the URL search string to specify. Any parameter given in the
|
|
23
|
+
* URL which is not listed will be ignored (e.g. you are unlikely to
|
|
24
|
+
* want to let the URL search string specify the `ajax` option).
|
|
25
|
+
*
|
|
26
|
+
* This specification is done by passing an array of property names
|
|
27
|
+
* to the `DataTable.deepLink` function. If you do which to
|
|
28
|
+
* allow _every_ parameter (I wouldn't recommend it) you can use `all`
|
|
29
|
+
* instead of an array.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Allow a display start point and search string to be specified
|
|
33
|
+
* new DataTable(
|
|
34
|
+
* '#example',
|
|
35
|
+
* DataTable.deepLink(['pageLength', 'search.search'])
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // As above, but with a default search
|
|
40
|
+
* var options = DataTable.deepLink(['displayStart', 'search.search']);
|
|
41
|
+
*
|
|
42
|
+
* new DataTable(
|
|
43
|
+
* '#myTable',
|
|
44
|
+
* DataTable.util.object.assignDeep({
|
|
45
|
+
* search: { search: 'Initial search value' }
|
|
46
|
+
* }, options)
|
|
47
|
+
* );
|
|
48
|
+
*/
|
|
49
|
+
DataTable.deepLink = function (whitelist) {
|
|
50
|
+
var search = location.search.replace(/^\?/, '').split('&');
|
|
51
|
+
var out = {};
|
|
52
|
+
for (var i = 0, ien = search.length; i < ien; i++) {
|
|
53
|
+
var pair = search[i].split('=');
|
|
54
|
+
var key = decodeURIComponent(pair[0]);
|
|
55
|
+
var value = decodeURIComponent(pair[1]);
|
|
56
|
+
// "Casting"
|
|
57
|
+
if (value === 'true') {
|
|
58
|
+
value = true;
|
|
59
|
+
}
|
|
60
|
+
else if (value === 'false') {
|
|
61
|
+
value = false;
|
|
62
|
+
}
|
|
63
|
+
else if (!value.match(/[^\d]/) && key !== 'search.search') {
|
|
64
|
+
// don't convert if searching or it'll break the search
|
|
65
|
+
value = value * 1;
|
|
66
|
+
}
|
|
67
|
+
else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
|
|
68
|
+
// Try to JSON parse for arrays and objects
|
|
69
|
+
try {
|
|
70
|
+
value = JSON.parse(value);
|
|
71
|
+
}
|
|
72
|
+
catch (e) { }
|
|
73
|
+
}
|
|
74
|
+
if (whitelist === 'all' || whitelist.indexOf(key) !== -1) {
|
|
75
|
+
var setter = DataTable.util.set(key);
|
|
76
|
+
setter(out, value, {});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export default DataTable;
|
|
84
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "datatables.net-feature-deeplink",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "DataTables plugin: Helper to allow deep links into a DataTable",
|
|
5
|
+
"main": "dist/dataTables.deepLink.js",
|
|
6
|
+
"module": "dist/dataTables.deepLink.mjs",
|
|
7
|
+
"types": "dist/dataTables.deepLink.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/*.css",
|
|
10
|
+
"dist/*.js",
|
|
11
|
+
"dist/*.mjs",
|
|
12
|
+
"dist/*.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/DataTables/Plugins.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"DataTables",
|
|
20
|
+
"plugins"
|
|
21
|
+
],
|
|
22
|
+
"author": "SpryMedia Ltd",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://datatables.net/forums"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://datatables.net",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"datatables.net": "^3.0.0-0"
|
|
30
|
+
}
|
|
31
|
+
}
|