Page 1 of 1
Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 5:35 pm
by MichaelBluejay
I'm storing my app's records in hidden fields, in the normal way (fields are tab-delimited, records are CR-delimited).
When the user choose which dataset they want to view, I'm taking the data from one of those fields and putting it into a Data Grid Table. The problem is that the hidden field contains more columns of data than I need to display. So I think my only option is to loop through all the records, manually adding the data only from the fields I want to a new container. This seems really inefficient.
What would be better would be a way to delete columns. For example:
put field data into theList
delete column 3 of theList
delete column 7 of theList
set the dgtext of group "displayData" to theList
Even better would be a way to specify what columns I want to import when setting dgtext:
set the dgtext of group "displayData" to columns 1,2,4,5,6,8,9,10 of theList
So, my questions are:
(1) Is there actually a one-liner that deletes columns from a container?
(2) Is there actually a way to specify only certain columns when populating a Data Grid Table?
(3) If no to both of the above, is there a better way to excise the unwanted columns besides looping through each record and building a new container? (And let's assume that I don't want to have to use an external database just to solve this problem.)
If #'s 1 and 2 don't actually exist, I'll add them as feature requests.
Thanks for your help!
Re: Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 5:54 pm
by dunbarx
Sort of.
Your data is delimited by tabs in each record. This allows you to parse the data easily. Set up a repeat loop
Code: Select all
on mouseUp
put yourData into temp
set itemdel to tab
repeat with y = 1 to the number of lines of temp
put item 1 of line y of temp & tab & item 3 of line y of temp & tab & item 4 of line y of temp into line y of newData
end repeat
put newData into fld "outPutField"
end mouseUp
I just chose 1,3 and 4 at random. There are cleverer ways to set the particular fields; I did it explicitly.
Craig Newman
Re: Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 6:26 pm
by MichaelBluejay
Thanks, but the whole point of my post was to see if there's a way to delete a column *without* building a new container.
Re: Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 8:32 pm
by FourthWorld
I think that in just about any system you'll be building a new container unless you use a columnar data store, which would be ultra-efficient for searches and this sort of columnar deletion but more costly with record-based tasks, and not directly supported by the DataGrid anyway.
Data stores are often cumbersome, but a well-written function can turn any operation into a one-liner.

Re: Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 10:15 pm
by dunbarx
If by "new container" you mean the variable used to collect the reformatted information (and the repeat loop to populate it?), that doesn't seem to me like much of a burden. Variables are free, and unless you have a whole lot of data, really a whole lot, very fast. They are only intermediaries in the process, and disappear after use.
You appear to easily know all this, and I get what you want as a feature. Is it really just the esthetic?
Re: Easy way to delete a column in a container?
Posted: Mon Jul 26, 2010 11:28 pm
by Zryip TheSlug
MichaelBluejay wrote:(1) Is there actually a one-liner that deletes columns from a container?
If by container you think to DataGrid, the way to delete a column is trivial:
Code: Select all
put the dgProp["columns"] of grp "MyGrid" into tListOfAllColumns -- Retrieve all the columns of the data grid "MyGrid".
delete line lineoffset(tColumnToDelete, tListOfAllColumns) of tListOfAllColumns -- Delete the required column
set the dgProp["columns"] of grp "MyGrid" to tListOfAllColumns -- Change the columns name list after the deletion
MichaelBluejay wrote:(2) Is there actually a way to specify only certain columns when populating a Data Grid Table?
Yes you can!
Internally a datagrid uses an array with a key for each column name.
For example if I have a grid with columns
Description Price Invisible
and I want to copy it in the Grid:
Description Price
I have to copy for each lines of the data gird, only the keys "Description" and "Price" from my first data grid to my second:
Code: Select all
repeat with x = 1 to tNumberOfLinesInGrid
put the dgDataOfLine[x] of grp "MyFirstGrid" into tTheSourceData -- Read the data of each line to copy
repeat for each line tColumnName in tColDestList
if (tColumnName is among lines of "Description" & cr & "Price") then -- Copy only key "Description" and "Price"
put tTheSourceData[tColumnName] into tTheDestData[tColumnName]
else
put empty into tTheDestData[tColumnName]
end if
end repeat
send "AddData tTheDestData" to grp "MySecondGrid" -- Add a line of data in the second DataGrid. This line contains only data for columns "Description" and "Price"
end repeat
Regards,
Re: Easy way to delete a column in a container?
Posted: Tue Jul 27, 2010 6:15 am
by MichaelBluejay
Thank you for the replies.
Dunbarx, I'd like a a simple way to delete a column for both aesthetics as well as performance. Rev makes it easy to say "delete line 5 of someContainer". By the same token, it seems logical that we should be able to do "delete column 3 of someContainer". Also, my experience is that built-in commands are generally faster than the ones I have to roll myself.
Zryip, your method of hiding/showing columns is very useful, thanks. Also interesting is that the data is still there, just hidden. I tested this method vs. building a new container (looping through each record and extracting just the fields I wanted), and hiding the dgprop column is way faster -- 4.5 seconds vs. 37 seconds on a dataset of 16,000 records with 6 columns to start with and omitting the 4th column. I don't expect to have 16k records, but this was a torture test to gauge relative performance.
Your second method isn't really any easier than just building a new container from the data, though.
So anyway, I think I have a solution for the time being -- Zryip's suggestion of hiding the unneeded columns. And since it doesn't look like Rev has a "column" chunk descriptor, I'll suggest that as a Feature Request in the other board.