[Dojo-interest] dgrid with REST dstore - new row, put data

Jean-Claude Hujeux jchujeux at gmail.com
Thu Feb 18 02:58:20 EST 2016


Hi Simon,

See below,
good luck,
jc
Le 18/02/2016 04:50, Simon Walter a écrit :
> On 2016/02/16 17:55, Jean-Claude Hujeux wrote:
>> My suggestions:
>>
>> #1: try :
>>
>>     restStore.add({/* I tried inserting data here, but it seems 
>>     unnecessary. */})/.then(function(){////grid.refresh(keepScrollPosition: true);////})/;
>>
>
> I tried this, and still there are no new rows added. My server is
> returning a JSON object like:
> {id: 3, name: "Japanese", code: "ja"}
> Is this enough to have new row added? Am I missing anything?

I'd say it should have worked, although I have no direct experience with
adding items to rest stores: so far I have chosen to use memory dstores
for dgrids that can be edited (did not feel like able to cope with added
complexity of deferred / promises and scroll/pagination in addition to
edition). Then when I add a row, I have the following code:

    grid.collection.addSync(item);
    grid.refresh(keepScrollPosition: true);

I can confirm that if I comment out the grid.refresh(), then the new
line does not show-up. It does if after this I change my browser window
size: this forces a refresh() or a resize(), not sure which one => you
may want to try this and see wether your new row appears.

Other than that, my suggestion is that you explore what goes on under
the debugger: I've learnt a lot this way.
>
>> #2: instead of:   self.grid.collection.put(self.value); // does not
>> seem to send the correct data (#2), try :
>>         /grid.save().then(function(){//
>> //                //whatever you wish to do once changed data on the
>> grid has been saved into grid.collection//
>> //       });
>>   /
>
> I think because I am going to try to use renderCell, and I want only
> the row whose save button is clicked to be saved, and not all the grid
> data that has changed, I will need to make some thing custom here.

OK

note that grid.save() empties grid.dirty, so it may still adress your
objective (assuming one would be forced to save before leaving a row he
has edited)

>
>>     you may not need self.value at all: grid keeps track of all
>> changes in grid.dirty.  What grid.save() does is send all those
>> changes back to grid.collection (and then for any cell that has
>> changed and on any row or column).
>>
>>     See here
>> <https://github.com/SitePen/dgrid/blob/v1.0.0/doc/components/core-components/OnDemandList-and-OnDemandGrid.md>for
>> explanations on refresh / save / dirty.
>>
>> #3: as said in post on Feb 1st, imho this is not do-able. Indeed it has to do with focus: when you set an 'onedit' value for the column, the column editor becomes shared for all cells of the column, and then it shows up when you focus in one cell, and disappears when you focus out. 
>>
>>
>> Rgds,
>> jc
>>
>> ps1: You might be able to achieve #3 by providing your own column.renderCell(), which would verify that you are on the row that you are currently editing and if this is the case, would return the dom construct that "mimics" the column editor widget, including the cell's current value. See here
>> <https://github.com/SitePen/dgrid/blob/v1.0.0/doc/components/core-components/Grid.md>for renderCell explanation
>>
>> ps2: maybe you could even use the shared editor instance for the column, returning grid._editorInstances[column.field]).domNode in that custom renderCell() ... (?) 
>
> I think I now understand what you mean about renderCell. I have had a
> look at the tests and will try somethings out and ask questions if I
> can't understand.
>
> Thanks again for the good info,
>
> Simon
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20160218/d0475d6f/attachment.htm 


More information about the Dojo-interest mailing list