-1

As you know, dgrid 0.4 now uses the dstore package instead of dojo's store. Using the Rest.js in dstore, I simply want to add a new row to the dgrid using a rest call. This works fine. However, it adds the row at the end (as the last row) of the dgrid. I need to add the row at the beginning (making the newly added row the first row of the dgrid). Inside Rest.js, there is a variable called defaultNewToStart which I figured would do the trick, but even when set to true, dgrid still adds the row at the end. Any advice on how to get Rest.js in dstore to add a row to the beginning of the dgrid.

user64141
  • 5,141
  • 4
  • 37
  • 34
  • 1
    Can you show your code, particularly how you are creating your store and grid, so we can see if there might be a commonly-overlooked mistake? – Ken Franqueiro Jan 16 '15 at 01:25
  • Yeah, it turns out I made a basic mistake that I bet someone would have caught. I'm never posting another question without relevant code again. – user64141 Jan 17 '15 at 05:46

2 Answers2

0

I figured out what I did wrong. In dgrid/OnDemandGrid, I set the property "sort", which was causing the queryExecutor in Trackable.js to put the newly added row at the end instead of the beginning. So all I had to do was remove the sort property, and now it works fine.

user64141
  • 5,141
  • 4
  • 37
  • 34
  • In your defense, this is not quite as common of a mistake as I suspected, and is a good one to note for future reference, so thanks for reporting on the results. – Ken Franqueiro Jan 17 '15 at 19:45
-1

The add function of dstore/Memory supports PutDirectives as second argument other than the item you are trying to insert. PutDirectives has a property beforeId which can be used to insert the item before any existing record in store.

To add an empty row at the beginning:

var beforeID = null;
store.fetch().forEach(lang.hitch(this, function(data) { beforeId = data.id;}));
store.add({id: ''}, {beforeId: beforeID});
gobernador
  • 5,659
  • 3
  • 32
  • 51