Page 1 of 1

ListIconGadget: Determine the underlying dgrid-Object?

Posted: Fri Aug 19, 2016 9:48 am
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

Re: ListIconGadget: Determine the underlying dgrid-Object?

Posted: Fri Aug 19, 2016 3:55 pm
by Fred
Not tested, but you should be able to use the 'gadget' field of the IsGadget() return value.

Re: ListIconGadget: Determine the underlying dgrid-Object?

Posted: Fri Aug 19, 2016 5:37 pm
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