cano63
asked on
dojo Grid
Can some body give a simple example on how to fill a dojo grid with a json string using the dojo version 1.3.2
Another one : http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_data_grid.html
json string here : http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/_data/countries.json
json string here : http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/_data/countries.json
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
@import "dojo/resources/dojo.css";
@import "dojox/grid/resources/Grid.css";
@import "dojox/grid/resources/tundraGrid.css";
body {
font-size: 0.9em;
font-family: Geneva, Arial, Helvetica, sans-serif;
}
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
#grid, #grid2 {
width: 65em;
height: 25em;
padding: 1px;
}
</style>
<script language="javascript" src="dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
</script>
</head>
<body>
<div class="heading">dojox.grid.DataGrid Basic Test</div>
<span dojoType="dojo.data.ItemFileWriteStore" jsId="jsonStore" url="countries.json"></span>
<table dojoType="dojox.grid.DataGrid" jsid="grid" id="grid" store="jsonStore" query="{ name: '*' }" rowsPerPage="20" rowSelector="20px">
<thead>
<tr>
<th field="name" width="300px">Country/Continent Name</th>
<th field="type" width="auto">Type</th>
</tr>
</thead>
</table>
</body>
</html>
A great article here : http://www.ibm.com/developerworks/web/library/wa-aj-dojogrid/index.html
A good link : http://www.sitepen.com/blog/2008/07/14/dojo-12-grid/
A good link : http://www.sitepen.com/blog/2008/07/14/dojo-12-grid/
ASKER
what about somthing that make a ajax request,
Where i,m lost here is how to manage my json string when i recieve it from the ajax call.
Where i,m lost here is how to manage my json string when i recieve it from the ajax call.
>what about somthing that make a ajax request,
dojo currently do an ajax request behind to get the data
>how to manage my json string when i recieve it from the ajax call.
you may to use fetch : youStore.fetch({onItem: doSomething})
for each data you call :
dojo currently do an ajax request behind to get the data
>how to manage my json string when i recieve it from the ajax call.
you may to use fetch : youStore.fetch({onItem: doSomething})
for each data you call :
function doSomething(item, request) {
// do what you want with the data
}
you've good example here where data is fetched :
http://docs.dojocampus.org/dojo/data/ItemFileWriteStore
http://docs.dojocampus.org/dojo/data/ItemFileReadStore
http://docs.dojocampus.org/dojo/data/ItemFileWriteStore
http://docs.dojocampus.org/dojo/data/ItemFileReadStore
if you want to work on the full json object you should use onComplete instead onItem.
Below an example where we modify the name of the countrie (uppercase) for each item (onItem event) :
(Save this : http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/_data/countries.json As : countries.json)
Below an example where we modify the name of the countrie (uppercase) for each item (onItem event) :
(Save this : http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/_data/countries.json As : countries.json)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
@import "dojo/resources/dojo.css";
@import "dojox/grid/resources/Grid.css";
@import "dojox/grid/resources/tundraGrid.css";
body {
font-size: 0.9em;
font-family: Geneva, Arial, Helvetica, sans-serif;
}
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
#grid, #grid2 {
width: 65em;
height: 25em;
padding: 1px;
}
</style>
<script language="javascript" src="dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: true"></script>
<script>
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.DataGrid");
dojo.require("dijit.form.Button");
function gotItem(item, request) {
var name = jsonStore.getValue(item, "name");
name = name.toUpperCase();
jsonStore.setValue(item, "name", name);
}
function getItems() {
jsonStore.fetch({onItem: gotItem});
}
dojo.addOnLoad(function init () {
var colorStore = new dojo.data.ItemFileWriteStore({url: "countries.json"});
});
</script>
</head>
<body onload="getItems();">
<span id="list"></span>
<span dojoType="dojo.data.ItemFileWriteStore" jsId="jsonStore" id="jsonStore" url="countries.json" ></span>
<table dojoType="dojox.grid.DataGrid" jsid="grid" id="grid" store="jsonStore" query="{ name: '*' }" rowsPerPage="20" rowSelector="20px">
<thead><tr><th field="name" width="300px">Country/Continent Name</th><th field="type" width="auto">Type</th></tr></thead>
</table>
</body>
</html>
ASKER
Thanks, a lot
What if my json come from a call from the servlet, in a respons object.
var colorStore = new dojo.data.ItemFileWriteSto re({url: "countries.json"});
when you choose the url option, how it work, it make a call to the server a get or post
like this
dojo.xhrGet( {
preventCache: "true",
url: "../StudentSearch,
handleAs: "json",
handle: SearchHandler
});
What if my json come from a call from the servlet, in a respons object.
var colorStore = new dojo.data.ItemFileWriteSto
when you choose the url option, how it work, it make a call to the server a get or post
like this
dojo.xhrGet( {
preventCache: "true",
url: "../StudentSearch,
handleAs: "json",
handle: SearchHandler
});
>What if my json come from a call from the servlet, in a respons object.
var colorStore = new dojo.data.ItemFileWriteSto re({url: "../StudentSearch"});
>when you choose the url option, how it work, it make a call to the server a get or post
A GET
var colorStore = new dojo.data.ItemFileWriteSto
>when you choose the url option, how it work, it make a call to the server a get or post
A GET
ASKER
this is what i have but is not working,
<style type="text/css">
@import "dojo/dojo/resources/dojo. css";
@import "dojo/dojox/grid/_grid/Gri d.css";
@import "dojo/dojox/grid/_grid/tun draGrid.cs s";
@import "dojo/dijit/themes/tundra/ tundra.css ";
@import "dojo/dijit/themes/dijit.c ss";
</style>
<script type="text/javascript" src="dojo/dojo/dojo.js"
djConfig="isDebug:false, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.dijit" );
dojo.require("dojox.grid.D ataGrid");
dojo.require("dojo.data.It emFileWrit eStore");
dojo.require("dojo.data.It emFileRead Store");
dojo.require("dojo.parser" );
</script>
<script>
var dataStore;
var layout = [
[{
field: "actor",
name: "Actor",
width: 10
},
{
field: "title",
name: "Titulo",
width: 'auto'
}]];
</script>
<script>
function init()
{
dataStore = new dojo.data.ItemFileWriteSto re({url: "/CallS"});
}
</script>
<script>
//dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
<form>
<div id="grid" style="width: 400px; height: 300px;" dojoType="dojox.grid.DataG rid"
store="dataStore" structure="layout"
rowsPerPage="40">
</div>
<input type="button" name="d" value="d" onclick="init()">
</form>
</body>
</html>
CallS is a servlet and in the get it have this
String title1 ="New1";
String title2 = "New2";
String actor1 = Brad";
String actor2 = "Oscar";
response.getOutputStream() .println(" {result:[{ actor:"+"\ ""+actor1+ "\",title: "+"\""+tit le1+"\"}," +
"{actor:"+"\""+actor2+"\", title:"+"\ ""+title2+ "\"}]");
<style type="text/css">
@import "dojo/dojo/resources/dojo.
@import "dojo/dojox/grid/_grid/Gri
@import "dojo/dojox/grid/_grid/tun
@import "dojo/dijit/themes/tundra/
@import "dojo/dijit/themes/dijit.c
</style>
<script type="text/javascript" src="dojo/dojo/dojo.js"
djConfig="isDebug:false, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.dijit"
dojo.require("dojox.grid.D
dojo.require("dojo.data.It
dojo.require("dojo.data.It
dojo.require("dojo.parser"
</script>
<script>
var dataStore;
var layout = [
[{
field: "actor",
name: "Actor",
width: 10
},
{
field: "title",
name: "Titulo",
width: 'auto'
}]];
</script>
<script>
function init()
{
dataStore = new dojo.data.ItemFileWriteSto
}
</script>
<script>
//dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
<form>
<div id="grid" style="width: 400px; height: 300px;" dojoType="dojox.grid.DataG
store="dataStore" structure="layout"
rowsPerPage="40">
</div>
<input type="button" name="d" value="d" onclick="init()">
</form>
</body>
</html>
CallS is a servlet and in the get it have this
String title1 ="New1";
String title2 = "New2";
String actor1 = Brad";
String actor2 = "Oscar";
response.getOutputStream()
"{actor:"+"\""+actor2+"\",
What about :
"identifier":"id","label": "name","it ems": [
something like :
(please call CallS directly in the browser and post the json string in code snipet)
"identifier":"id","label":
something like :
(please call CallS directly in the browser and post the json string in code snipet)
response.getOutputStream().println("{"identifier":"id","label":"name","items": [{actor:"+"\""+actor1+"\",title:"+"\""+title1+"\"}," + "{actor:"+"\""+actor2+"\",title:"+"\""+title2+"\"}]");
ASKER
This is what i et in the webbrowser
{result:[{actor:"Jose",title:"Nueva1"},{actor:"Omar",title:"Nueva2"}]
It's not a valid json object miss an << } >>at the end to close the object
{result:[{actor:"Jose",title:"Nueva1"},{actor:"Omar",title:"Nueva2"}]}
try this :
response.getOutputStream() .println(" {\"identif ier\":\"id \",\"label \":\"name\ ",\"items\ :[{actor:" +"\""+acto r1+"\",tit le:"+"\""+ title1+"\" },{\"actor \":"+"\""+ actor2+"\" ,\"title\" :"+"\""+ti tle2+"\"}] }");
response.getOutputStream()
ASKER
this is the new response
The Stange thing is that i put the server in debug and add a breake point in the servlet, the system is not hitting the servlet. url option should make an ajax get request ?
The Stange thing is that i put the server in debug and add a breake point in the servlet, the system is not hitting the servlet. url option should make an ajax get request ?
Put a doPost to for testing purpose
ASKER
well i try something like this and it hit the server, but the url is not hitting it
dojo.xhrGet( {
preventCache: "true",
url: "../StudentSearch,
handleAs: "json",
handle: SearchHandler
});
dojo.xhrGet( {
preventCache: "true",
url: "../StudentSearch,
handleAs: "json",
handle: SearchHandler
});
ASKER
this is what i have now but still no hitting the servlet
Don,t know what i,m missing
this is whta return my servlet
{identifier:"actor",items: [{actor:"j ose",title :"pedro"}, {actor:"jo se",title: "pedro"}]}
Don,t know what i,m missing
this is whta return my servlet
{identifier:"actor",items:
<script>
var dataStore;
var layout = [
[{
field: "actor",
name: "Actor",
width: 10
},
{
field: "title",
name: "Titulo",
width: 'auto'
}]];
</script>
<script>
function initX()
{
dataStore = new dojo.data.ItemFileReadStore({url: "CallEspecialistasS"});
}
</script>
<script>
//dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
<form>
<div id="grid" style="width: 400px; height: 300px;" dojoType="dojox.grid.DataGrid"
store="dataStore" structure="layout"
rowsPerPage="40">
</div>
<input type="button" name="d" value="d" onclick="initX()">
</form>
</body>
>Don,t know what i,m missing
fast look :
fast look :
<span dojoType="dojo.data.ItemFileWriteStore
you don't define label too
The following servlet work for me :
the "identifier" must be unique
if you choose "actor" as "identifier" you can't have twice "jose" .
the "identifier" must be unique
if you choose "actor" as "identifier" you can't have twice "jose" .
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CallEspecialistasS extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
String actor1 = "jose1", title1="pedro";
String actor2 = "jose2", title2="pedro";
response.setContentType("application/json");
response.getOutputStream().println("{\"identifier\":\"actor\",\"label\":\"title\",\"items\":[{\"actor\":\"" + actor1 + "\", \"title\":\"" + title1 +"\"},{\"actor\":"+"\"" + actor2 + "\", \"title\":" + "\"" + title2 + "\"}]}");
}
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
doGet(request, response);
}
}
ASKER
Ok, Finally is working fine. Thanks a lot
But what about i want to display the grid but with the filtered data, i know that i have to send the parameter in the url to the get in the servlet, but how i can destroy this grid and create a new one, i try but it just create me a new grid with the new values, but let me the other one so i have to grids
But what about i want to display the grid but with the filtered data, i know that i have to send the parameter in the url to the get in the servlet, but how i can destroy this grid and create a new one, i try but it just create me a new grid with the new values, but let me the other one so i have to grids
function lod() {
// our test data store for this example:
var store4 = new dojo.data.ItemFileReadStore({url: "CallEspecialistasS"});
// set the layout structure:
var layout4 = [{field: 'actor', name: 'Actor', width: '80px'}, {field: 'title',name: 'Title',width: 'auto'}];
// create a new grid:
var grid4 = new dojox.grid.DataGrid({store: store4,clientSort: true,rowSelector: '20px',structure: layout4 },
document.createElement('div'));
// append the new grid to the div "gridContainer4":
dojo.byId("gridContainer4").appendChild(grid4.domNode);
// Call startup, in order to render the grid:
grid4.startup();};
</script>
<body class="tundra">
<form>
<div id="gridContainer4" style="width: 50%; height: 20%;">
</div>
<input type="button" name="3" value="3" onclick="lod()">
</form>
>how i can destroy this grid and create a new one
no need, you can filter the current content of the datagrid :
gridContainer4.filter({act or:"jose1* "}); // filter all value where the actor value start by "jose1"
no need, you can filter the current content of the datagrid :
gridContainer4.filter({act
You've an example here : http://docs.dojocampus.org/dojox/grid/DataGrid
look for the << Filtering data >> example
look for the << Filtering data >> example
ASKER
I dont want to filter the data that i have displayed, i want to display totaly new data, that why i wany to destroy it a create a new one with diferent data.
same page : http://docs.dojocampus.org/dojox/grid/DataGrid
<< Refreshing the content of a grid >>
we create a new store and set is as stor for the grid
<< Refreshing the content of a grid >>
we create a new store and set is as stor for the grid
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Greate Support, Thanks
You're very welcome! Thanks a lot for the points!
ASKER