Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ 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;
- `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`;
- `updateUrl` - the URL used to update data;
- `insertUrl` - the URL used to insert data;
Expand All @@ -89,6 +91,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
Expand Down
5 changes: 4 additions & 1 deletion js/dx.aspnet.data.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import CustomStore from "devextreme/data/custom_store";

interface Options {
key?: string|Array<string>,
key?: string|Array<string>,

allUrl?: string,
byKeyUrl?: string,

loadUrl?: string,
loadParams?: Object,
Expand Down
30 changes: 21 additions & 9 deletions js/dx.aspnet.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@

function createStoreConfig(options) {
var keyExpr = options.key,
loadUrl = options.loadUrl,
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) {
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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] ];
});
}
);
Expand Down