Moving items between Data Grids (table & form) and working with row templates

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
markosborne
Posts: 15
Joined: Sat Mar 20, 2010 6:03 pm

Moving items between Data Grids (table & form) and working with row templates

Post by markosborne » Thu Feb 23, 2023 5:20 pm

Hello All,

The app I’m developing has two Data Grids: Display A (table) and Display B (form).

The data is being pulled from a database when the stack is opened (connecting directly from the LiveCode app for the moment). Each entry in the dataset contains three items: text_to_display, alt_text & ref_num.

This works fine and the data is being stored in an array and the dgData of Display A (the Data Grid table) is being set:

Code: Select all

set the dgData of group “DataGrid_A" of card "A" to gDataGridArray
The Data Grid is sized so that only the first column - with text_to_display - is visible. The other two columns are populated with data but not visible (alt_text, ref_num).

The Data Grid form is empty in its initial state.

So far, so good (probably).

Users are then able to scroll through lists of items in Data Grid A and move items they are interested in over to Data Grid B (think of Data Grid B as being similar to shopping basket - a temp store).

The way this is envisaged being implemented is that users select items in Data Grid A (one at a time for the time being). When an item has been selected they can then click an “add” button on the card, which will move the selected item from Data Grid A (table) into Data Grid B (form).

When an item has been moved to Data Grid B (form), it has two buttons in addition to the original text in the row: a “view” button and a “remove” button. The “view” button will display further information about that item (based on ref_num). If an item is viewed, the “remove” button becomes disabled (only items that have not been viewed can be removed). The “remove” button deletes the item from Data Grid B and returns it to Data Grid A (in its original position relative to the other items in Data Grid A).

This is partially implemented. I am using a row template with a field “txt” and two buttons “view” & “remove” for Data Grid B (Data Grid form).

“add” button script:

Code: Select all

global gDataGridArray, gDataGridArray_temp

on mouseUp
   
 put the dgData of group "DataGridA" into theDataGridArray_DI_temp
  
   put the dgHilitedIndexes of group "DataGridA" into pIndex
   put theDataGridArray_temp[pIndex]["text_to_display"] into pItemArray["text_to_display"]
   put theDataGridArray_temp[pIndex][“ref_num”] into pItemArray["ref_num"]
  
   dispatch "AddData" to group "DataGridB" with pItemArray, 1
   
  dispatch "DeleteIndex" to group “DataGridA" with pIndex
    
end mouseUp
I am seeking advice on:

a) How to reference the “remove” button from the script of the “view” button (in the row template);

Code: Select all

global gDataGridArray_DI, gDataGridArray_DI_temp

The is the script of the “remove“ button:

on mouseUp
   
   put the dgData of group "DataGrid_temp" into gDataGridArray_DI_temp
   put the dgHilitedIndexes of group "DataGridB" into pIndex
   put theDataGridArray_DI_temp[pIndex]["text_to_display"] into pItemArray["text_to_display"]
   put theDataGridArray_DI_temp[pIndex]["ref_num"] into pItemArray["ref_num"]

   dispatch "AddData" to group "DataGridA" with pItemArray, pItemArray[“ref_num”]

   dispatch "DeleteIndex" to group "DataGridB" with pIndex
   
end mouseUp
It works (removes the item from Data Grid B and adds it back to Data Grid A). But it doesn't always maintain the original relative index position. Plus, I can’t work out how to make the “remove” button disabled if the “view” button is clicked.

b) How to put items back from Data Grid B into the correct index of Data Grid A (in their original position relative to the other items in Data Grid A (NB: some items from Data Grid A may have been removed from Data Grid A and currently be in Data Grid B).

NB: ref_num may or may not be the same as index and it is not intended to be (see “remove” button script above). ref_num is intended to be used as a reference to access additional information about the item stored elsewhere in the stack;

c) How to store/access the ref_num value so that additional information can be displayed to the user when the “view” button is clicked.

Hope this all makes sense. The code is work in progress and I'm sharing it so that hopefully you get a better idea of where I'm at with it.

Any contributions gratefully accepted.

Thanks in advance

Mark

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”