[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,
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
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?
gits 5,390
Recognized Expert Moderator Expert
hi ...
ok ... let me give you an example for the dom-handling: - <html>
-
<script type="text/javascript">
-
function handle_rows() {
-
var table = document.getElementById('t1');
-
var rows = table.getElementsByTagName('tr');
-
-
// remove all rows
-
while (rows.length > 0) {
-
table.removeChild(table.lastChild);
-
rows = table.getElementsByTagName('tr');
-
}
-
-
// create a new one
-
var nr = document.createElement('tr');
-
var nc = document.createElement('td');
-
var t = document.createTextNode('new text');
-
-
// appending now:
-
nc.appendChild(t);
-
nr.appendChild(nc);
-
table.appendChild(nr);
-
}
-
</script>
-
<body>
-
<table id="t1">
-
<tr>
-
<td>test1</td>
-
</tr>
-
<tr>
-
<td>test2</td>
-
</tr>
-
</table>
-
<input type="button" onclick="handle_rows();" value="handle rows"/>
-
</body>
-
</html>
-
kind regards
hi ...
ok ... let me give you an example for the dom-handling: - <html>
-
<script type="text/javascript">
-
function handle_rows() {
-
var table = document.getElementById('t1');
-
var rows = table.getElementsByTagName('tr');
-
-
// remove all rows
-
while (rows.length > 0) {
-
table.removeChild(table.lastChild);
-
rows = table.getElementsByTagName('tr');
-
}
-
-
// create a new one
-
var nr = document.createElement('tr');
-
var nc = document.createElement('td');
-
var t = document.createTextNode('new text');
-
-
// appending now:
-
nc.appendChild(t);
-
nr.appendChild(nc);
-
table.appendChild(nr);
-
}
-
</script>
-
<body>
-
<table id="t1">
-
<tr>
-
<td>test1</td>
-
</tr>
-
<tr>
-
<td>test2</td>
-
</tr>
-
</table>
-
<input type="button" onclick="handle_rows();" value="handle rows"/>
-
</body>
-
</html>
-
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,
I got some idea how to do this filter stuff, will defeneitly share with all once it complete :)
gits 5,390
Recognized Expert Moderator Expert
ok ... i'm looking forward to it :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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).
|
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 + ')');
};
|
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,
|
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...
| |
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...
|
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...
|
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.
|
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; }
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |