Ticket T477561
Visible to All Users

dxDataGrid - How to update a certain row using SignalR

created 8 years ago

I have an editable grid that uses a custom store (built using the https://github.com/DevExpress/DevExtreme.AspNet.Data/blob/master/js/dx.aspnet.data.js create store).

I also get update notifications from the server when data in this grid is changed. I want the grid to update that row as the data flows in (from signalR). Ideally if the user is editing that row at the time, they'd just get a notification or something.

How can I update a row in the grid without causing it to call the update method on the custom store?

I was thinking that I could maybe back a custom store with an array store to cache the data locally - but when I call the update method from JS I would need to stop it from calling the AJAX method. But perhaps there is another way I can achieve this?

Thanks,
David

Answers approved by DevExpress Support

created 8 years ago (modified 8 years ago)

Hi David,

Use the dxDataGrid.repaintRows method to redraw the specified rows. The https://jsfiddle.net/r4gfha0b/ example shows how to accomplish a similar task. You can use it as a starting point for your scenario.

UPDATED BY Alessandro (DevExpress Support Team):

  1. You can handle the onEditingStart/onRowUpdated events to pause/resume the timer in order to avoid updates when the editing state is active. I have modified your sample accordingly: https://jsfiddle.net/z95f2gw1/.

  2. This is default behavior of the classic editing modes ("form", "row", "cell"). Please consider the Batch Mode if you wish to postpone data saving until the end-user clicks the Save button.

    Show previous comments (7)
    DC DC
    David Collis 3 8 years ago

      Ok, thanks for help. I have a reasonable workaround where at least on refreshing the grid on refresh it goes to the local arraystore rather than triggering another request to the server.

      My (messy, sorry) code is here, in case anyone finds it useful:

      JavaScript
      function getCustomStore(url, objectKey) { var fixStore = DevExpress.data.AspNet.createStore({ key: objectKey, loadUrl: url, updateUrl: url }); var store = new DevExpress.data.CustomStore({ key: objectKey, load: function(loadOptions) { var d = $.Deferred(); if (store.localRefresh) { d.resolve(store.innerStoreData); } else { var ajax = fixStore.load(loadOptions); ajax.done(function(result) { store.innerStoreData.length = 0; store.innerStoreData.push.apply(store.innerStoreData, result); d.resolve(store.innerStoreData); }); } store.localRefresh = false; return d.promise(); }, byKey: function(key, extra) { return this.innerStore.byKey(key, extra); }, update: function(key, values) { var d = $.Deferred(); var ajax = fixStore.update(key, values); ajax.done(function(result) { this.innerStore.update(key, values); d.resolve(result); }); return d.promise(); }, insert: function(data) { return this.innerStore.insert(data); } }); store.localRefresh = false; store.innerStoreData = []; store.innerStore = new DevExpress.data.ArrayStore({ data: store.innerStoreData, key: objectKey }); store.localUpdate = function(key, values, grid) { store.innerStore.byKey(key) .done(function () { //we don't want to update the row being edited - it'll be refreshed by the server after update var rowIndexToUpdate = grid.getRowIndexByKey(key); if(store.editingRow !== rowIndexToUpdate){ store.innerStore.update(key, values) .done(function() { var rowIndex = grid.getRowIndexByKey(key); grid.getController('data').updateItems({ changeType: 'update', rowIndices: [rowIndex] }); }); } }) .fail(function () { store.innerStore.insert(values) .done(function() { store.localRefresh = true; grid.refresh(); }); }); } return store; }

        Why UpdateItems doe's not raising any grid events ?!

        Alessandro (DevExpress Support) 7 years ago

          Hi,

          This method only refreshes the visual state of required rows. It does not perform any CRUD operations. Note that latest versions of our dxDataGrid component have a public repaintRows method (see T510485: dxDataGrid - How to enable live inserting/deleting). Should you need further clarification, feel free to ask. I will be happy to help you.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.