0

Please help.
Short scenario:
I select 5 records/rows in a grid, set the value, in 1 of their column, to 'Not Steuart'.
So 5 rows got changed in grid.

When I use button on the toolbar, toolbarSave: true, nothing happens,

What do I need to use to save changed rows, back to .json file ?
Do I need to code it in 'onSubmit' ?

Data is read from file: 'url: 'data/DataFromCsv11.json'.
My code below.

Thank you very much,
Waldemar

==========================================================

var mySelection;

function setSelectedRecords() {
  mySelection = w2ui.grid.getSelection();
  //w2alert(mySelection.length);
  for (var i = 0; i < mySelection.length; i++) {
    w2ui['grid'].set(mySelection[i], {changes:{REVIEWER:'Not Steuart'}
    });
  }
};
Waldemar
  • 5
  • 3

1 Answers1

0

If you define url as a string, the grid will send a post request with the changes to this url.

Since your url points to a json file, that's probably not what you want.

You can however define url as an object:

$('#grid').w2grid({
    name : 'grid',
    url  : {
        get    : 'server/side/path/to/records',
        remove : 'server/side/path/to/remove',
        save   : 'server/side/path/to/save'
    },

the "get" part can still point to your json file, the "save" part should point to an url on your server that will handle the changes.

Another option could be to overwrite the grid's onSave() event and send the changed data with $.ajax(...) to whereever you want.

It is up to you to handle the posted data on the server side.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
  • Thanks Mike, your answer got me thinking. Maybe my approach to this is wrong. I was trying to test the w2ui grid without live db access. Hence I created a .json file with 500 records. Manipulated some of them in grid and expected the grid to save the changes back to .json. This may not be the best way to prove that the grid is working. Still looking for better ideas until I get that db access. – Waldemar Mar 23 '16 at 17:01
  • @Waldemar: You're welcome. Your browser can't magically write to the server or to a local file. A work-around until you have DB access could be to overwrite the onSave() event, build your updated JSON file and provide the file to the user as a download. You might want to take a look at https://github.com/eligrey/FileSaver.js if you want to do that. – Mike Scotty Mar 24 '16 at 15:22