• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to implement filtering in large Data Set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to implement filtering in large Data Set


  • Subject: Re: Best way to implement filtering in large Data Set
  • From: Keith Duncan <email@hidden>
  • Date: Sun, 15 Apr 2007 11:09:21 +0100

Forget filtering at the NSTableView level.
Use an NSArrayController to handle the actual data array (which accepts filtering, ordering, etc.) and then bind the NSTableView to the NSArrayController.

Given that you appear to be working with a datasource then I'll work with that, but unless you have a very specific case need for it I too would recommend looking at NSArrayController it will vastly simplify your code and lets you get away without writing a datasource.


However if you do want to use a datasource (or if you can't use NSArrayController 'cos you aren't on panther) I'd say the best way to go about this is to have two ivars, trivially NSArray *content, *arrangedContent.

Now what would be the best way to implement both "objectValueForTableColumn" and "numberOfRowsInTableView" as the filtering starts.

The best way to implement filtering is to use a predicate. I'm assuming you're on tiger. Read up on how to construct these in the documentation but the important method you'll need is the NSArray method -(NSArray *)filteredArrayUsingPredicate:(NSPredicate *) predicate; which will return a subarray of objects matching the predicate.


You'd have to make sure that the arrangedContent was updated when ever any other relevant ivars are changed, the content, the search string (which, presumably, you'll construct the predicate from) and anything else I haven't thought of. Then you'd just have to tell the table view -(void)reloadData in the accessor for arrangedContent. FInally you'd have your datasource methods pull objects from the arrangedContent array.

Since you mention this is going to be a large data set, once you have already filtered the content array once there is no need to filter the entire content array again should the search be restricted further. In this case you'd only apply the new predicate to the existing arrangedContent, but be careful - if the search constraints are *changed* you'll have to apply it to the whole content array.

- Keith
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Best way to implement filtering in large Data Set (From: Micha Fuhrmann <email@hidden>)

  • Prev by Date: Re: CGEventKeyboardGetUnicodeString + modifier key
  • Next by Date: Re: Best way to implement filtering in large Data Set
  • Previous by thread: Re: Best way to implement filtering in large Data Set
  • Next by thread: NSDrawer border width
  • Index(es):
    • Date
    • Thread