ListIconGadget: Determine the underlying dgrid-Object?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

ListIconGadget: Determine the underlying dgrid-Object?

Post by Peter »

Hello,

below there is a (cumbersome) snippet to detect if a columnheader was clicked (for example to sort the displayed data).

I wonder, how to determine the underlying dgrid-Object for an easy access to all dgrid-functionalities.

Code: Select all

EnableExplicit

Enumeration
  #myWindow
  #myListIconGadget
EndEnumeration

OpenWindow(#myWindow, #PB_Ignore, #PB_Ignore, 800, 600, "ListIconGadget", #PB_Window_ScreenCentered)

ListIconGadget(#myListIconGadget, 10, 10, WindowWidth(#myWindow) - 20, WindowHeight(#myWindow) - 20, "FirstColumn", 100)

AddGadgetColumn(#myListIconGadget, 1, "SecondColumn", 100)

Define Counter

For Counter = 0 To 9
  AddGadgetItem(#myListIconGadget, -1, "FirstColumnValue" + Str(Counter) + #LF$ + "SecondColumnValue" + Str(Counter))
Next

Define GadgetID = GadgetID(#myListIconGadget)
Define SelectedColumn

! $(v_gadgetid.div).find(".dgrid").find(".dgrid-header-row").find("th").on("click", function(e) { 
!   v_selectedcolumn = $(e.currentTarget).index();
Debug "HeaderClick detected!"
Debug "SelectedColumn: " + Str(SelectedColumn)
! });
Greetings ... Peter
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: ListIconGadget: Determine the underlying dgrid-Object?

Post by Fred »

Not tested, but you should be able to use the 'gadget' field of the IsGadget() return value.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: ListIconGadget: Determine the underlying dgrid-Object?

Post by Peter »

Hello Fred,

thank you for pointing into the right direction! :) (it's GadgetID(); not IsGadget())

Code: Select all

Define GadgetID = GadgetID(#myListIconGadget)
Define ColumnIndex

! var grid = v_gadgetid.gadget;
! grid.on('.dgrid-header .dgrid-cell:click', function (event) {
!  var column = grid.column(event);
!  v_columnindex = column.index;
Debug "HeaderClick detected!"
Debug "Column: " + Str(ColumnIndex)
! });
Greetings ... Peter
Post Reply