From 2947d1fb8a83b9d63b1a3d7ab9751be23c7322dd Mon Sep 17 00:00:00 2001 From: "ruben.suarez" Date: Fri, 28 Oct 2016 14:28:11 +0200 Subject: [PATCH 1/2] Bootstrap Table Defer URL Extension When using server-side processing, the default mode of operation for bootstrap-table is to simply throw away any data that currently exists in the table and make a request to the server to get the first page of data to display. This is fine for an empty table, but if you already have the first page of data displayed in the plain HTML, it is a waste of resources. As such, you can use data-defer-url instead of data-url to allow you to instruct bootstrap-table to not make that initial request, rather it will use the data already on the page. --- src/extensions/defer-url/README.md | 17 +++++++++ .../defer-url/bootstrap-table-defer-url.js | 37 +++++++++++++++++++ src/extensions/defer-url/extension.json | 17 +++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/extensions/defer-url/README.md create mode 100644 src/extensions/defer-url/bootstrap-table-defer-url.js create mode 100644 src/extensions/defer-url/extension.json diff --git a/src/extensions/defer-url/README.md b/src/extensions/defer-url/README.md new file mode 100644 index 0000000000..875bf8df03 --- /dev/null +++ b/src/extensions/defer-url/README.md @@ -0,0 +1,17 @@ +# Table Defer URL + +Use Plugin: [bootstrap-table-defer-url](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/defer-url) + +## Usage + +```html + +``` + +## Options + +### deferUrl + +* type: String +* description: When using server-side processing, the default mode of operation for bootstrap-table is to simply throw away any data that currently exists in the table and make a request to the server to get the first page of data to display. This is fine for an empty table, but if you already have the first page of data displayed in the plain HTML, it is a waste of resources. As such, you can use data-defer-url instead of data-url to allow you to instruct bootstrap-table to not make that initial request, rather it will use the data already on the page. +* default: `null` diff --git a/src/extensions/defer-url/bootstrap-table-defer-url.js b/src/extensions/defer-url/bootstrap-table-defer-url.js new file mode 100644 index 0000000000..0870aa4ebb --- /dev/null +++ b/src/extensions/defer-url/bootstrap-table-defer-url.js @@ -0,0 +1,37 @@ +/** + * When using server-side processing, the default mode of operation for + * bootstrap-table is to simply throw away any data that currently exists in the + * table and make a request to the server to get the first page of data to + * display. This is fine for an empty table, but if you already have the first + * page of data displayed in the plain HTML, it is a waste of resources. As + * such, you can use data-defer-url instead of data-url to allow you to instruct + * bootstrap-table to not make that initial request, rather it will use the data + * already on the page. + * + * @author: Ruben Suarez + * @webSite: http://rubensa.eu.org + * @version: v1.0.0 + */ + +(function($) { + 'use strict'; + + $.extend($.fn.bootstrapTable.defaults, { + deferUrl : undefined + }); + + var BootstrapTable = $.fn.bootstrapTable.Constructor, _init = BootstrapTable.prototype.init; + + BootstrapTable.prototype.init = function() { + _init.apply(this, Array.prototype.slice.apply(arguments)); + + if (this.options.deferUrl) { + this.options.url = this.options.deferUrl; + } + + // reset variable to original initServer function, so that future calls + // to initServer + // use the original function from this point on. + BootstrapTable.prototype.initServer = _initServer; + } +})(jQuery); \ No newline at end of file diff --git a/src/extensions/defer-url/extension.json b/src/extensions/defer-url/extension.json new file mode 100644 index 0000000000..4895fb21d0 --- /dev/null +++ b/src/extensions/defer-url/extension.json @@ -0,0 +1,17 @@ +{ + "name": "DeferURL", + "version": "1.0.0", + "description": "Plugin to defer server side processing.", + "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/defer-url", + "example": "http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/defer-url.html", + + "plugins": [{ + "name": "bootstrap-table-defer-url", + "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/defer-url" + }], + + "author": { + "name": "rubensa", + "image": "https://avatars1.githubusercontent.com/u/1469340" + } +} \ No newline at end of file From ff3d8b4d3c8f6e81dfa19e94831c1577d45705c0 Mon Sep 17 00:00:00 2001 From: "ruben.suarez" Date: Thu, 3 Nov 2016 16:46:40 +0100 Subject: [PATCH 2/2] Bugfix: Removed wrong code. --- src/extensions/defer-url/bootstrap-table-defer-url.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/extensions/defer-url/bootstrap-table-defer-url.js b/src/extensions/defer-url/bootstrap-table-defer-url.js index 0870aa4ebb..25d2a17358 100644 --- a/src/extensions/defer-url/bootstrap-table-defer-url.js +++ b/src/extensions/defer-url/bootstrap-table-defer-url.js @@ -7,7 +7,7 @@ * such, you can use data-defer-url instead of data-url to allow you to instruct * bootstrap-table to not make that initial request, rather it will use the data * already on the page. - * + * * @author: Ruben Suarez * @webSite: http://rubensa.eu.org * @version: v1.0.0 @@ -28,10 +28,5 @@ if (this.options.deferUrl) { this.options.url = this.options.deferUrl; } - - // reset variable to original initServer function, so that future calls - // to initServer - // use the original function from this point on. - BootstrapTable.prototype.initServer = _initServer; } })(jQuery); \ No newline at end of file