0
votes

I have a dgrid with 2 columns: Name, Predecessor.

Each row has another row as predecessor, which I am setting it to be. The order of the rows is not relevant for this.

In the predecessor column I choose from a list the name of another row as a predecessor.

My problem is that when I change the name of the row after I set it as a predecessor to another row, It would not automatically change with the new name (which is expected). Of course after a manual refresh of the page I will see the new name.

How can I manually change the name of the row in the wanted cell without manually refreshing the page or without using the grid.refresh() method after the save() has been made? For example setting a value in a cell in the callback of the save() function.

I am using dojo.store.JsonRest. And I am using the grid.save() method to send the PUT request to my store. The sore is a PHP page which rends it's response back to the grin in JSON.

My grid looks like this:

    <table id="myGrid" data-dojo-props="query:{param: 'value'}">
    <tr>
    <th data-dgrid-column="editor({field:'name',id:'name',width:175,sortable:false, unhidable:true,formatter:'do_highlight',editor:TextBox,editOn:'dblclick'})">Name</th>
    <th data-dgrid-column="{field:'predecesors', id:'predecesors', width:175, sortable:false,renderCell:milestones.render_predecessor}">Predecessor</th>
    </tr>                                        
    </table> 

My save function called on the "dgrid-datachange" event, looks like this:

this.end_edit = function(event){
    var item = event.grid.store.get(event.cell.row.id);
    item.__edited_field = event.cell.column.field;
    event.grid.updateDirty(event.cell.row.id, field, new_value);
    var def = event.grid.save();
    def.then(null, ajax.show_error);
}

If someone has an idea how to refresh that specific cell I would much appreciate. I would like to avoid the refresh() function because it gives me errors.

1

1 Answers

0
votes

There are generally 2 things required in order for the grid to update rows automatically based on store changes:

  • The store needs to be observable
  • The store needs to have a query engine, in order for Observable to know where items belong

JsonRest doesn't include a queryEngine by default, because query engines generally need to know information that, in JsonRest's case, depends on server behavior. However, in simple cases, you can get away with using dojo/store/util/SimpleQueryEngine anyway (which is what Memory uses by default).

So you'd end up with something like:

var store = new Observable(new JsonRest({
    target: '...',
    queryEngine: SimpleQueryEngine
}));

If you need to force other rows to re-render, you can achieve this by manually calling either store.put or store.notify (the former if you really want to send it back to the server, the latter if you just want to update it in the UI - notify is normally used to allow the client to respond to further server updates).