473,511 Members | 13,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apply Filters using JSON

101 New Member
[PHP]{"length":50,"accounting":[
{"firstName":"John","lastName":"Doe","age":23},
{"firstName":"Mary","lastName":"Smith","age":32 },
{"firstName":"Sally","lastName":"Green","age":2 3},
{"firstName":"Jim","lastName":"Galley","age":41 }
]}
[/PHP]
I am rendering the above JSON object in a tabel using DOM .

Now i want to add a functionality of Filters means
There is some check box specifying age

if I select 23 age check box it display all the data where age is 23
the table only render those records.

If i unselect the check box it render all the records without filter.


Please help how to do this

Regards,
Nov 6 '07 #1
6 2985
gits
5,390 Recognized Expert Moderator Expert
hi ...

onclick of your checkbox you should identify its checked-property and call a function that loops through your (json-data) and grabs the appropriate records from it. with that you create new table-row-elements with table-cells and their texts. remove all current table-rows and append the new rows ... you may have a look at the following dom-methods for that issue:

createElement();
removeChild();
appendChild();
createTextNode();

kind regards
Nov 6 '07 #2
buntyindia
101 New Member
hi ...

onclick of your checkbox you should identify its checked-property and call a function that loops through your (json-data) and grabs the appropriate records from it. with that you create new table-row-elements with table-cells and their texts. remove all current table-rows and append the new rows ... you may have a look at the following dom-methods for that issue:

createElement();
removeChild();
appendChild();
createTextNode();

kind regards
Any example is available on the net for this?
Nov 7 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

ok ... let me give you an example for the dom-handling:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.    <script type="text/javascript">
  3.        function handle_rows() {
  4.            var table = document.getElementById('t1');
  5.            var rows  = table.getElementsByTagName('tr');
  6.  
  7.            // remove all rows
  8.            while (rows.length > 0) {
  9.                table.removeChild(table.lastChild);
  10.                rows = table.getElementsByTagName('tr');
  11.            }
  12.  
  13.            // create a new one
  14.            var nr = document.createElement('tr');
  15.            var nc = document.createElement('td');
  16.            var t  = document.createTextNode('new text');
  17.  
  18.            // appending now:
  19.            nc.appendChild(t);
  20.            nr.appendChild(nc);
  21.            table.appendChild(nr);
  22.        }
  23.    </script>
  24.    <body>
  25.         <table id="t1">
  26.             <tr>
  27.                 <td>test1</td>
  28.             </tr>
  29.             <tr>
  30.                 <td>test2</td>
  31.             </tr>
  32.         </table>
  33.         <input type="button" onclick="handle_rows();" value="handle rows"/>
  34.    </body>
  35. </html>
  36.  
kind regards
Nov 7 '07 #4
buntyindia
101 New Member
hi ...

ok ... let me give you an example for the dom-handling:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.    <script type="text/javascript">
  3.        function handle_rows() {
  4.            var table = document.getElementById('t1');
  5.            var rows  = table.getElementsByTagName('tr');
  6.  
  7.            // remove all rows
  8.            while (rows.length > 0) {
  9.                table.removeChild(table.lastChild);
  10.                rows = table.getElementsByTagName('tr');
  11.            }
  12.  
  13.            // create a new one
  14.            var nr = document.createElement('tr');
  15.            var nc = document.createElement('td');
  16.            var t  = document.createTextNode('new text');
  17.  
  18.            // appending now:
  19.            nc.appendChild(t);
  20.            nr.appendChild(nc);
  21.            table.appendChild(nr);
  22.        }
  23.    </script>
  24.    <body>
  25.         <table id="t1">
  26.             <tr>
  27.                 <td>test1</td>
  28.             </tr>
  29.             <tr>
  30.                 <td>test2</td>
  31.             </tr>
  32.         </table>
  33.         <input type="button" onclick="handle_rows();" value="handle rows"/>
  34.    </body>
  35. </html>
  36.  
kind regards

Thanks gits for the example :)

but gits how to handle JSON data to get a Filtered Data on clicking of checkBox and to restore the original data after unchecking the check box ?

[PHP] {"length":50,"accounting":[
{"firstName":"John","lastName":"Doe","age":23},
{"firstName":"Mary","lastName":"Smith","age":32 },
{"firstName":"Sally","lastName":"Green","age":2 3},
{"firstName":"Jim","lastName":"Galley","age":41 }
]}[/PHP]


Please provide some help/example on this.... I am very urgent need of this ...

Regards,
Nov 10 '07 #5
buntyindia
101 New Member
I got some idea how to do this filter stuff, will defeneitly share with all once it complete :)
Nov 11 '07 #6
gits
5,390 Recognized Expert Moderator Expert
ok ... i'm looking forward to it :)
Nov 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

16
2665
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post...
20
6808
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
8
10390
by: Douglas Crockford | last post by:
There is a new version of JSON.parse in JavaScript. It is vastly faster and smaller than the previous version. It uses a single call to eval to do the conversion, guarded by a single regexp test to...
2
3731
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
2
3297
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
6
5122
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
1
2614
by: Andrew Burton | last post by:
I'm poking at a small "single page application" (SPA), ala TiddlyWiki, to act as kind of a local, single-user version of Twitter (no real application, except to familiarize myself with JavaScript)....
23
3171
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
7
16125
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.