473,671 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apply Filters using JSON

101 New Member
[PHP]{"length":50,"a ccounting":[
{"firstName":"J ohn","lastName" :"Doe","age":23 },
{"firstName":"M ary","lastName" :"Smith","age": 32},
{"firstName":"S ally","lastName ":"Green","age" :23},
{"firstName":"J im","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 2991
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,"a ccounting":[
{"firstName":"J ohn","lastName" :"Doe","age":23 },
{"firstName":"M ary","lastName" :"Smith","age": 32},
{"firstName":"S ally","lastName ":"Green","age" :23},
{"firstName":"J im","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
2690
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 he calls what I am suggesting "brittle", his own Javascript JSON parser is not valid JSON, but rather conforms to my proposed variation on JSON!! With an identifier prepended to the front of the JSON block, and function literals as values: see...
20
6849
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... PS i am ready to use JSON as data/object interchange when using AJAX and my J2EE project - because it is easier to traverse the JavaScript object than its XML representation (so of course may argue).
8
10407
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 assure that it is safe. JSON.parse = function (text) { return (/^(\s|]|"(\\|)*"|-?\d+(\.\d*)?(?\d+)?|true|false|null)+$/.test(text)) && eval('(' + text + ')'); };
2
3744
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 considered bad practice because it can disrupt the use of for in loops on Objects. Am I incorrect? Thanks,
2
3313
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 recently -- or maybe I should just speak for myself.) The fact that JSON is more elegant goes without saying, yet I can't seem to find a way to use JSON the way I *really* want to use it: to create objects that can be instantated into multiple...
6
5142
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 application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
1
2621
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). Right now I'm using a hidden field to hold JSON, which is currently my flat-file database of posts. Is there a better way to store JSON data in a SPA other than hidden fields? I'm Googling now to allay or confirm my concerns, but I'm...
23
3196
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 an object.
7
16153
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
8478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8397
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7439
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.