From 7e94bbd40615db460b6dce898ca137731a346c64 Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 17:30:17 +1000 Subject: [PATCH 1/8] Update dx.aspnet.data.js Added byKeyURL. Enables the user to specify the URL to use when fetching using the /api/controller/id or similar pattern. E.g. using a store productStore and specifying byKeyURL as http://example.com/api/product, a call to productStore.byKey(5) will yield a request; http://example.com/api/product/5 This is instead of the devexpress default by which it would use the loadURL and append a filter. --- js/dx.aspnet.data.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/js/dx.aspnet.data.js b/js/dx.aspnet.data.js index 4a278931..b084fc4e 100644 --- a/js/dx.aspnet.data.js +++ b/js/dx.aspnet.data.js @@ -35,6 +35,7 @@ function createStoreConfig(options) { var keyExpr = options.key, loadUrl = options.loadUrl, + byKeyURL = options.byKeyURL, loadParams = options.loadParams, updateUrl = options.updateUrl, insertUrl = options.insertUrl, @@ -132,6 +133,18 @@ return result; } + function getByKeyProperties(keyValue) + { + if (byKeyURL) return { + url: byKeyURL + '/' + keyValue, + data: loadOptionsToActionParams() + }; + else return { + url: loadUrl, + data: loadOptionsToActionParams({ filter: filterByKey(keyValue) }) + } + } + return { key: keyExpr, @@ -168,16 +181,15 @@ }, byKey: function(key) { + var keyProps = getByKeyProperties(key); return send( "load", true, - { - url: loadUrl, - data: loadOptionsToActionParams({ filter: filterByKey(key) }) - }, + keyProps, function(d, res) { processLoadResponse(d, res, function(res) { - return [ res.data[0] ]; + if (byKeyURL) return [ res ]; + else return [ res.data[0] ]; }); } ); From 4954ecb8cd3a470a5d0d4cbb0e64f80e968ea45e Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 17:31:06 +1000 Subject: [PATCH 2/8] Update dx.aspnet.data.d.ts Added property to support byKeyURL --- js/dx.aspnet.data.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/dx.aspnet.data.d.ts b/js/dx.aspnet.data.d.ts index d67c1db0..50d02813 100644 --- a/js/dx.aspnet.data.d.ts +++ b/js/dx.aspnet.data.d.ts @@ -1,7 +1,9 @@ import CustomStore from "devextreme/data/custom_store"; interface Options { - key?: string|Array, + key?: string|Array, + + byKeyURL?: string, loadUrl?: string, loadParams?: Object, From 86ef6663960c3e4412c65c0cd3d5e66b07da3007 Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 17:54:13 +1000 Subject: [PATCH 3/8] Update dx.aspnet.data.js Fixed case --- js/dx.aspnet.data.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/dx.aspnet.data.js b/js/dx.aspnet.data.js index b084fc4e..a1167d8a 100644 --- a/js/dx.aspnet.data.js +++ b/js/dx.aspnet.data.js @@ -35,7 +35,7 @@ function createStoreConfig(options) { var keyExpr = options.key, loadUrl = options.loadUrl, - byKeyURL = options.byKeyURL, + byKeyUrl = options.byKeyUrl, loadParams = options.loadParams, updateUrl = options.updateUrl, insertUrl = options.insertUrl, @@ -135,8 +135,8 @@ function getByKeyProperties(keyValue) { - if (byKeyURL) return { - url: byKeyURL + '/' + keyValue, + if (byKeyUrl) return { + url: byKeyUrl + '/' + keyValue, data: loadOptionsToActionParams() }; else return { @@ -188,7 +188,7 @@ keyProps, function(d, res) { processLoadResponse(d, res, function(res) { - if (byKeyURL) return [ res ]; + if (byKeyUrl) return [ res ]; else return [ res.data[0] ]; }); } From 74b0f83e810daa41b6afdb059078f98c5b721605 Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 17:58:52 +1000 Subject: [PATCH 4/8] Update dx.aspnet.data.d.ts Fixed case --- js/dx.aspnet.data.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/dx.aspnet.data.d.ts b/js/dx.aspnet.data.d.ts index 50d02813..9d314965 100644 --- a/js/dx.aspnet.data.d.ts +++ b/js/dx.aspnet.data.d.ts @@ -3,7 +3,7 @@ import CustomStore from "devextreme/data/custom_store"; interface Options { key?: string|Array, - byKeyURL?: string, + byKeyUrl?: string, loadUrl?: string, loadParams?: Object, From 24ec6f2b170fcffd96cfa5b7d4c99184d29b8d35 Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 18:19:46 +1000 Subject: [PATCH 5/8] Update README.md Explained byKeyUrl parameter --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea2fca5b..9e502465 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,8 @@ The server needs a custom model binder that will receive data loading options fr To reach the controller from the client side, use the `DevExpress.data.AspNet.createStore` method. It accepts an object with the following fields. - `key` - the key property; -- `loadUrl` - the URL used to load data; +- `loadUrl` - the URL used to load data; +- `byKeyUrl` - a URL to override the default behaviour when requesting a record by key. See below for rationale - `loadParams` - additional parameters that should be passed to `loadUrl`; - `updateUrl` - the URL used to update data; - `insertUrl` - the URL used to insert data; @@ -89,6 +90,10 @@ To reach the controller from the client side, use the `DevExpress.data.AspNet.cr You can find an example [here](https://github.com/DevExpress/DevExtreme.AspNet.Data/blob/master/net/Sample/Views/Home/Index.cshtml). +The byKeyUrl allows the store to specify a different URL for requests than the default, which uses loadUrl. This is useful when the loadURL implements additional logic that is unnecessary for the byKey function, or when they return different result sets - e.g. when the loadURL returns a Dto with miniimal fields to populate a list, whereas the byKeyUrl returns the full object. + +If myProductStore isset to http://www.example.com/api/products, then the function myProductStore.byKey(5) will issue the request http://www.example.com/api/products/5 instead of the default where the request would be http://www.example.com/api/products with a filter ['ProductId','=','5']. + DevExtreme ASP.NET MVC Controls call the `DevExpress.data.AspNet.createStore` method internally. To configure the parameters, use the lambda expression of the `DataSource()` method. ```Razor From 0281d1811f1a916b1893346be60c6511fd2adf82 Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 18:51:06 +1000 Subject: [PATCH 6/8] Update README.md Added allUrl --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e502465..45f369a4 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,8 @@ The server needs a custom model binder that will receive data loading options fr To reach the controller from the client side, use the `DevExpress.data.AspNet.createStore` method. It accepts an object with the following fields. -- `key` - the key property; +- `key` - the key property; +- `allUrl` - the URL used for all operations unless overridden by loadUrl, byKeyUrl, insertUrl etc.; - `loadUrl` - the URL used to load data; - `byKeyUrl` - a URL to override the default behaviour when requesting a record by key. See below for rationale - `loadParams` - additional parameters that should be passed to `loadUrl`; From 1908e0e025247df1944bac29fdaac9c2926f65af Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 18:52:24 +1000 Subject: [PATCH 7/8] Update dx.aspnet.data.d.ts --- js/dx.aspnet.data.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/dx.aspnet.data.d.ts b/js/dx.aspnet.data.d.ts index 9d314965..30b657c0 100644 --- a/js/dx.aspnet.data.d.ts +++ b/js/dx.aspnet.data.d.ts @@ -1,8 +1,9 @@ import CustomStore from "devextreme/data/custom_store"; interface Options { - key?: string|Array, + key?: string|Array, + allUrl?: string, byKeyUrl?: string, loadUrl?: string, From a0e04d30a2047b95af20dea67a57f40378cc028f Mon Sep 17 00:00:00 2001 From: statler <337991+statler@users.noreply.github.com> Date: Fri, 15 Sep 2017 18:56:15 +1000 Subject: [PATCH 8/8] Update dx.aspnet.data.js AllURL options added --- js/dx.aspnet.data.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/dx.aspnet.data.js b/js/dx.aspnet.data.js index a1167d8a..2bce2331 100644 --- a/js/dx.aspnet.data.js +++ b/js/dx.aspnet.data.js @@ -34,12 +34,12 @@ function createStoreConfig(options) { var keyExpr = options.key, - loadUrl = options.loadUrl, - byKeyUrl = options.byKeyUrl, + byKeyUrl = options.byKeyUrl || options.allUrl, + loadUrl = options.loadUrl || options.allUrl, loadParams = options.loadParams, - updateUrl = options.updateUrl, - insertUrl = options.insertUrl, - deleteUrl = options.deleteUrl, + updateUrl = options.updateUrl || options.allUrl, + insertUrl = options.insertUrl || options.allUrl, + deleteUrl = options.deleteUrl || options.allUrl, onBeforeSend = options.onBeforeSend; function send(operation, requiresKey, ajaxSettings, customSuccessHandler) {