Author Topic: How to Implement AutoSave and nested tables?  (Read 4223 times)

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
How to Implement AutoSave and nested tables?
« on: August 22, 2016, 02:01:59 am »
I have a jsfiddle here.
http://jsfiddle.net/jeremy_b/mLt4xyLk/1/

My problem is that I can't get the auto-save function to trigger on changes to the detailModel table(s).

Thanks..

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #1 on: August 22, 2016, 10:26:43 am »
Subject should be How to Implement Auto Save and Row Detail.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6264
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #2 on: August 22, 2016, 03:06:14 pm »
Your jsfiddle code is taken from batch editing, so I've updated it for batch editing example for you.

http://jsfiddle.net/mLt4xyLk/3/

Couple of things to note:

1. Avoid global variables especially with nested/ row details.
2. Pass grid instance to common shared functions like saveChanges.
3. Take grid instance from context of events, callbacks.
4. Enable trackModel for detailModel too.

Hope it helps.
« Last Edit: August 22, 2016, 03:08:36 pm by paramquery »

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #3 on: August 23, 2016, 01:12:55 am »
lol, I took a jsfiddle I found in the forums that was close enough to what I needed and modified it..

I took your suggestions and came up with this:
http://jsfiddle.net/jeremy_b/mLt4xyLk/4/

From the main grid all I care about are, add a row, delete a row, auto save name and expand somehow..
On the detail grid all I care about is auto updating when a checkbox is checked.

In my revised code auto-update works except when delete is pressed saveChanges isn't called.

Also wondering is there a better way to present this information..
eg: when you click on a row the column "Secret Names" it automatically expands and when you click on another row it collapses while the next row expands.
« Last Edit: August 23, 2016, 05:27:24 am by jeremy »

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #4 on: August 23, 2016, 06:27:50 am »
Or perhaps something like this? (Doesn't work functional how I want but visually sort of)
http://jsfiddle.net/jeremy_b/mLt4xyLk/6/

Basically a single row, and in that single row there are check boxes for different options to enable..
Fields I want to be able to modify are
Name & Active..

If it's not asking too much I'd love to be able to add another "Name" with all blank Actives.
« Last Edit: August 23, 2016, 06:32:47 am by jeremy »

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #5 on: August 23, 2016, 08:46:05 am »
Okay... I think I got it perfect with regular nested grids:

http://jsfiddle.net/jeremy_b/mLt4xyLk/7/

only problem is postRender doesn't fire for the delete button so delete doesn't work.
it would be cool if I could collapse the previous row, but it's not mission critical.

Thanks for the advice

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6264
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #6 on: August 23, 2016, 09:18:18 am »
Quote
  only problem is postRender doesn't fire for the delete button so delete doesn't work.

Add postRenderInterval: -1 to the grid initialization options.

Quote
  it would be cool if I could collapse the previous row, but it's not mission critical.

Add this code in beforeRowExpand event to collapse other rows.
Code: [Select]
beforeRowExpand: function(evt, ui){
              var data = this.option('dataModel.data');
              for(var i=0, len = data.length; i< len; i++){
              var detail = data[i].pq_detail;
                if(detail && detail.show){
                detail.show = false;
                }               
              }
              this.refresh();
            },

http://jsfiddle.net/mLt4xyLk/8/

jeremy

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to Implement AutoSave and nested tables?
« Reply #7 on: August 23, 2016, 09:22:30 am »
Awesome, it works.. thank you for your assistance. :-)