c# - Xamarin IMobileServiceTable Not Filtering -


i'm using imobileservicetable in data access layer class , bind listview. initial loading works fine filtering doesn't. returns initial loaded data.

public class itemsmanager {      imobileservicetable<item> itemtable;      public itemsmanager (imobileservicetable<item> todotable)      {         this.itemtable = todotable;     }       public async task<list<item>> gettasksasync (string searchstring)     { //following doesn't work             var list = new list<item> (await itemtable.where(x => x.itemid.contains(searchstring)).tolistasync());             return list;      }      public async task<list<item>> gettasksasync ()     {             return new list<item> (await itemtable.orderby(a =>a.itemid).tolistasync());      }  } 

if matter, following page code :

public partial class itemslistxaml : contentpage {     imobileservicetable<item> itemtable;     itemsmanager itemmanager;      public itemslistxaml ()     {          initializecomponent ();         itemtable = app.client.gettable<item>();          itemmanager = new itemsmanager(itemtable);          app.setitemsmanager (itemmanager);     }      protected async override void onappearing ()     {         base.onappearing ();         listview.itemssource = await itemmanager.gettasksasync ();     }      async void  onvaluechanged (object sender, textchangedeventargs e) {         var t = e.newtextvalue;         // perform search on min 3 keypress         if (t.length>3) {             listview.itemssource = await itemmanager.gettasksasync(searchfor.text);         }     } } 

it looks problem line this:

var list = new list (await      itemtable.where(x => x.itemid.contains searchstring)).tolistasync()); 

not sure what's going on there, did manage similar working. sample have uses proxy object save on azure fetches. fetch once initial list of tasks , save local observablecollection object can bind list. then, can filter collection object bound list (sample here).

you might have legitimate reasons fetching filtered list azure. in mind - , bear me because i'm no expert on app design - unless there significant period of time between initial fetch of list , filter action there might new data introduced table, seems filtering local object perform better , cheaper. app handle push notifications update list needed.

basically, pull objects azure shown here:

public async task<observablecollection<todoitem>> gettasksasync() {     try     {         return new observablecollection<todoitem>(await _todotable.readasync());     }     catch (mobileserviceinvalidoperationexception msioe)     {         debug.writeline(@"invalid {0}", msioe.message);     }     catch (exception e)     {         debug.writeline(@"error {0}", e.message);     }     return null; } 

then, bind list shown here:

protected async override void onappearing() {     base.onappearing();      app.todomanager.todoviewmodel.todoitems = await app.todomanager.gettasksasync();      listviewtasks.itemssource = app.todomanager.todoviewmodel.todoitems; } 

in example, “app.todomanager.todoviewmodel.todoitems” qualified path proxy object observablecollection.

then can filter proxy object , rebind list. haven’t implemented part in sample, did take down copy of , added code , seems work fine. code:

getting filtered list:

public observablecollection<todoitem> getfilteredlist(string searchstring) {     return new observablecollection<todoitem>     (todoviewmodel.todoitems.where(x => x.name.contains(searchstring))); } 

calling helper method , binding listview (incorporating 1 of example blocks):

async void  onvaluechanged (object sender, textchangedeventargs e) {     var t = e.newtextvalue;     // perform search on min 3 keypress     if (t.length>3) {        app.todomanager.todoviewmodel.todoitems = app.todomanager.getfilteredlist(searchfor.text);         listviewtasks.itemssource = app.todomanager.todoviewmodel.todoitems;       } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -