In my Grails project I have a GSP page with a JQuery table, with buttons that allows me to add / remove rows. I've created it following the tutorial here
I have implemented the save of table values inside DB (they refers to a domain class fields and objects, so I use the save()
method of related controller), but I don't know how to fill the table with correct data in instance edit()
method of controller.
Is there a way to add rows into a table in a gsp page from the controller, when user edits the instance?
First and dirty way to do above task is to put your table code into a gsp template and update it by the response from Ajax request. But it's not optimize as in this way you have to request whole data again and again.
Second and more optimize way is to use javascript templating like Mustache or Hogan.JS. In this case you just need to request data in json format and then template will do all the work for you.
Third way is that you can use third part jquery based table to do all the work like display table, add, delete and edit any row data in it. Two of the most popular are Data Table and JqGrid.
Fourth and most optimize way of all is to leave Ajax and adopt AngularJS to do al the work like loading data, modifying data etc