Getting the values from the selected row of a table?
-
I need to get the value of the primary key (shown in the table) of the
selected row of my table, no matter how the table is sorted interactively.
I'm able to get the selected row index, but this seems to give the
"geographic" index of the selected row in the table, as sorted.
So far, I've solved my problem by ensuring that the table source is sorted
by it's primary key, and blocking sorting in the table itself. This is not
too bad for my application (in it's current state, at least), but
eventually I'd like to be able to sort the table interactively and map the
selection back to the original data.
I'm using IB and key value binding, and registering a notification to get
the fact of selection did change.
Thanks,
John Velman -
On Oct 7, 2008, at 2:55 PM, John Velman wrote:> I'm able to get the selected row index, but this seems to give the
> "geographic" index of the selected row in the table, as sorted.
Why don't you get the selected object from your array controller
directly, then ask it for the value of its primary key attribute?
Otherwise, if you want (or for some reason need) to look it up by
its selected row, you're most likely asking your array controller for
its array, right? Ask it for its -arrangedObjects, *then* determine
the index of that object.
Overall, though, it sounds like you're not quite getting Bindings
(particularly the controller layer's role in Bindings) and could
probably benefit from another perusal of the documentation (or a few
well-chosen questions here).
--
I.S. -
Well, you're undoubtedly right that I'm "not quite getting bindings" yet,
but I'm a lot closer than I was. I'll ponder what you've suggested and see
whether I "get it" or can come up with some better questions!
Thanks,
John V.
On Tue, Oct 07, 2008 at 03:10:27PM -0400, I. Savant wrote:> On Oct 7, 2008, at 2:55 PM, John Velman wrote:
>
>> I'm able to get the selected row index, but this seems to give the
>> "geographic" index of the selected row in the table, as sorted.
>
> Why don't you get the selected object from your array controller
> directly, then ask it for the value of its primary key attribute?
>
> Otherwise, if you want (or for some reason need) to look it up by its
> selected row, you're most likely asking your array controller for its
> array, right? Ask it for its -arrangedObjects, *then* determine the index
> of that object.
>
> Overall, though, it sounds like you're not quite getting Bindings
> (particularly the controller layer's role in Bindings) and could probably
> benefit from another perusal of the documentation (or a few well-chosen
> questions here).
>
> --
> I.S.
> -
On 8 Oct 2008, at 5:55 am, John Velman wrote:> I'm able to get the selected row index, but this seems to give the
> "geographic" index of the selected row in the table, as sorted.
Because a table is a view, the selection is purely "geographic", since
the table's job is to map an item of data to a location on screen.> So far, I've solved my problem by ensuring that the table source is
> sorted
> by it's primary key, and blocking sorting in the table itself. This
> is not
> too bad for my application (in it's current state, at least), but
> eventually I'd like to be able to sort the table interactively and
> map the
> selection back to the original data.
When the table is sorted, its delegate is notified to actually perform
the sort of the data. Just make a note of which item(s) are selected,
perform the sort, then update the selection to the new positions of
the existing selected items.
Remember that the table view itself is not part of your data model. It
shows exactly what you want it to show - if its concept of "selection"
is not appropriate for your data model, then maintain the selection in
the data model and drive the table view to match.
hth,
Graham


