views:

105

answers:

1

My json data looks like this,

{"Table" : [{"accid" : "13","accname" : "Default","accountType" : "Default",
"noOfEmployes" : "","phone" : "","revenue" : "","webSite" : ""},
{"accid" : "15","accname" : "karpagam","accountType" : "Customer",
"noOfEmployes" : "60","phone" : "9894606677","revenue" : "","webSite" : ""},
{"accid" : "14","accname" : "VLB","accountType" : "Customer",
"noOfEmployes" : "60","phone" : "9865636371","revenue" : "","webSite" : ""},
{"accid" : "12","accname" : "XIT","accountType" : "Customer",
  "noOfEmployes" : "20","phone" : "4347980","revenue" : "1000000",
     "webSite" : "xavyinfotech.com"}]}

Now i have a textbox account name where my user can enter an account name like D,d,kar any character and now i want to match that text to my accname keys of my json data. My filter may produce 'n' number of results.. Any suggestion to Filter json data using jquery?

EDIT:

Should i depend on other libraries like jslinq to do so?

+1  A: 

No need for jQuery.

for (el in data.Table) {
  if (somecondition(el.accname) {
    dosomethingwith(el);
  }
}
Ignacio Vazquez-Abrams
@Ignacio will this remove all other rows during filter?
Pandiya Chendur
No. It will merely iterate through the rows and allow you to process the ones you're interested in.
Ignacio Vazquez-Abrams
@Ignacio i think you misunderstood my question... I want to filter in my json object without iterating through it...
Pandiya Chendur
@Ignacio then i ll use the new json object to display my yui datatable...
Pandiya Chendur
You cannot filter without iterating somehow. What you do with the positive elements is your choice, but I'd add them to the control. Or another array if whatever you're using needs one.
Ignacio Vazquez-Abrams
@Ignacio ok i ll try this and let you know...
Pandiya Chendur