How Can I Have Only One Drawer (in Queue) Open at a Time?

  • 2
  • Question
  • Updated 8 months ago
  • Answered
Basically, all I'm looking for is a way to have an open drawer close when opening a new one via the queue item action. Don't see anything obvious in the action framework. Thanks.
Photo of Mark Tucker

Mark Tucker

  • 412 Points 250 badge 2x thumb

Posted 3 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
There really isn't anything obvious.  Saving the model will close all drawers in the table - but this results in some other unanticipated negative experience.  It might work in your case, who knows....
Photo of Mark Tucker

Mark Tucker

  • 412 Points 250 badge 2x thumb
Thanks. Any plans to add more api support on component behaviors?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Mark,

I haven't tested this in a queue, but here's a snippet we use in a table to ensure that only one drawer is open at a time:

// Run immediately after open/close drawer action to close other drawers.
var args = arguments[0],
thisID = args.item && args.item.drawers && args.item.drawers[0]._GUID,
tems = args.list.visibleItems,
drawer,
$ = skuid.$;
$.each(items,function(index,item){
drawer = item.drawers && item.drawers[0];
if (drawer && (drawer._GUID !== thisID) && drawer.isOpen) {
drawer.close();
}
});
Photo of Mark Tucker

Mark Tucker

  • 412 Points 250 badge 2x thumb
Thanks, Matt. Honestly forgot this post existed. Will keep this in the toolbox for an appropriate time in the future. Thanks!
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
I tried this and got a uncaught error, item is not defined.  Tried it on a queue, because I wanted the other queue drawers to close when I selected another one.

the reason I want it to do that is because I have items in my drawer repeating.

Example:

Click Queue Item 1:
See in drawer: SubItem 1, SubItem 2

Click Queue Item 2:
See in drawner: SubItem 3, SubItem 4

Model is set to merge new data in, and my context is all set.  Good so far.

Click on Queue Item 1 again
See in drawer: SubItem1, SubItem 2, SubItem1, SubItem 2

So my sub items in my drawer are duplicating.  That is what I am trying to fix.

My thought was if I could close the other drawers, I could change the query to be a standard / replace, rather than merge with old.  I don't mind the other drawers of the queue staying open, just trying to get rid of the duplicates when I click on the queue item for a 2nd time.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Chandra,

Make sure that your query action for the subitems is in the 'before load actions' of the drawer definition, not in the on-click action of the parent queue.
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
Thanks Matt!!  I got it working. :D One small typo in case anyone else reads this... Line 3 above
tems = args.list.visibleItems,

Should be

items = args.list.visibleItems,
Photo of Tim Shores

Tim Shores

  • 508 Points 500 badge 2x thumb
Works great for me!