Getting data from DataSource

This is probably very easy, but I can’t figure out how to do it. I have a data source and from Apple’s documentation I know I can do the following to get the data of the data source back in a list of lists form:


set myList to contents of every data cell of every data row of theDataSource

where theDataSource is a data source. Now the question is, I only want to get back a subset of rows - the rows whose first data cell has content true (boolean). I tried this


set myList to contents of every data cell of every data row of theDataSource whose contents of data cell 1 is true

but it didn’t work. I tried to replace “data cell 1” with “first data cell” and it still didn’t work.

Any suggestion is much appreciated.

Does this work:

set the_table to table view 1 of scroll view 1 of window "main"
set the_data_source to data source of the_table
tell the_data_source
    return contents of data cells of (data rows whose contents of data cell 1 of it = true)
end tell

Jon

I got error “Can’t get item 2 of true. (-1728)”

It works fine for me. Take a look at this quick demo project:

http://homepage.mac.com/jonn8/as/dist/get_rows.hqx

Jon

Hey Jon,

I’ve seen in a couple of your demo projects that you use an “ASKDataSource” instance in your MainMenu.nib file. Just wondering how that differs from something like this:

on awake from nib the_object_
    if the name of the_object_ is "table_view" then
        set not_converted_data_source_ to make new data source at the end of data sources with properties {name:"notConvertedTable"}
        make new data column at end of data columns of not_converted_data_source_ with properties {name:"file_"}
        make new data column at end of data columns of not_converted_data_source_ with properties {name:"reason_"}
        set data source of the_object_ to not_converted_data_source_
    end if
end awake from nib

Is using that “make new data source at end of data sources” kind of like creating an “ASKDataSource” instance programmatically?

I thought I saw somewhere that the “append with” command that you use to set the contents of the data source is faster than using a “set the_row_ to make new data row at end of the data rows of not_converted_data_source_” and then doing “set contents of data cell “file_” of the_row_ to the_data_” for each column in the data source? But to use that “append with” method, you need to have the “ASKDataSource” instance in the .nib file rather than creating it programmatically?

You’re right and wrong. Yes, creating the data source programatically is the same as adding it to the nib. The reason I do this is because it saves me two lines of code. And you’re also right that “append with” is much faster than looping through the data and building a table row by row. You’re wrong, however, in thinking that you can’t use the “append” command with a data source you created programatically. I amended the get_rows project to demonstrate doing it both programatically and using a prebuilt data source:

http://homepage.mac.com/jonn8/as/dist/get_rows.hqx

Jon

PS You may have to Option-Click the link above to get your browser to download a fresh copy and not use the cached version.