|
Invité de passage
Inscription : avril 2011 Messages : 2 Détails du profil  Informations forums : Inscription : avril 2011 Messages : 2 Points : 0 Points : 0
|
apres quelques modifications, et la suppression du cache de firefox qui faisait buguer le tout, le code suivant fonctionne
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
</style>
<script src="dojoroot_1.6/dojo/dojo.js"
djConfig="parseOnLoad: true">
</script>
<script>
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.XmlStore");
var layoutBooks = [
[{
field: "titre",
name: "Titre du Film",
width: 'auto'
},
{
field: "style",
name: "Style",
width: 'auto'
},
{
field: "resume",
name: "Resume",
width: 'auto'
},
{
field: "sortie",
name: "Annee",
width: 'auto'
},
{
field: "langue",
name: "Langue",
width: 'auto'
}]];
</script>
<link rel="stylesheet" type="text/css" href="dojoroot_1.6/dijit/themes/claro/claro.css"
/>
<style type="text/css">
@import "dojoroot_1.6/dojox/grid/resources/Grid.css";
@import "dojoroot_1.6/dojox/grid/resources/nihiloGrid.css";
.dojoxGrid table { margin: 0; }
</style>
</head>
<body class=" claro ">
<div dojoType="dojox.data.XmlStore" url="carnetMysqlToXml.xml"
jsId="bookStore3" label="repertoire">
</div>
<div id="grid" style="min-height:800px;width: 100%; height: 100%;" dojoType="dojox.grid.DataGrid"
store="bookStore3" structure="layoutBooks" query="{}" rowsPerPage="40">
</div>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
dojo.addOnLoad(function() {
if (document.pub) {
document.pub();
}
});
</script>
</body>
</html> |
maintenant, la seconde passe consiste a changer le type de store utilisé, a savoir le dojox.data.xmlstore pour passer une une évolution trouvable ici http://dojotoolkit.org/reference-gui...store-examples qui consiste a fournir directement une string XML a la place de l'URL d'un fichier, utile si on récupère les données a mettre dans la grid par requete SQL.
voici le code utilisé:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
</style>
<script src="dojoroot_1.6/dojo/dojo.js" djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.XmlStore");
dojo.require("dojox.xml.parser");
dojo.ready
(
function()
{
hookXmlStore();
var myxml ="";
var args=
{
url:"sql.php",
handleAs:"json",
sync:true,
handle:function(data)
{
//alert(data);
myxml=data;
},
error:function(error)
{
alert(error);
},
content:
{
"action":"xml",
"request":"select * from film"
}
};
dojo.xhrGet(args);
var store = new my.data.XmlStringStore
(
{
xmlstring: myxml,
label: "description"
}
);
var layoutBooks=
[
[
{
field: "titre",
name: "Titre du Film",
width: 'auto'
},
{
field: "style",
name: "Style",
width: 'auto'
},
{
field: "resume",
name: "Resume",
width: 'auto'
},
{
field: "sortie",
name: "Annee",
width: 'auto'
},
{
field: "langue",
name: "Langue",
width: 'auto'
}
]
];
var grid4=new dojox.grid.DataGrid
(
{
store:"store",
structure:"layoutBooks",
query:"{}",
rowsPerPage:"40"
},
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();
}
);
hookXmlStore = function()
{
dojo.declare
(
"my.data.XmlStringStore",
[dojox.data.XmlStore],
{
constructor: function(args)
{
this.inherited("constructor", arguments);
this.xmlstring = args.xmlstring;
this.url = "dummy.xml";
},
_fetchItems: function(request, fetchHandler, errorHandler)
{
var url = this._getFetchUrl(request);
if (!url)
{
errorHandler(new Error("No URL specified."));
return;
}
var localRequest = (!this.sendQuery ? request : {});
var data = dojox.xml.parser.parse(this.xmlstring);
var items = this._getItems(data, localRequest);
if (items && items.length > 0)
{
fetchHandler(items, request);
}
else
{
fetchHandler([], request);
}
}
}
);
};
</script>
<style type="text/css">
@import "dojoroot_1.6/dojox/grid/resources/Grid.css";
@import "dojoroot_1.6/dojox/grid/resources/nihiloGrid.css";
@import "dojoroot_1.6/dijit/themes/claro/claro.css"
.dojoxGrid table { margin: 0; }
</style>
</head>
<body class=" claro ">
<div id="gridContainer4">
</div>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
dojo.addOnLoad(function() {
if (document.pub) {
document.pub();
}
});
</script>
</body>
</html> |
encore une fois, la majorité du code est pompé de la référence dojo.
le script plante à la construction de la grid avec l'erreur suivante de firebug
:
perso, je reconnais ne jamais avoir compris quoi que ce soit à ce type d'erreur la  .
si j'ai bien suivi le debugger, ca a l'air de planter quand il veux relier grid4 à sa div html mais pas sur...
edit:
le code suivant ne bugue plus, l'erreur se situait sur les propriétés d'initialisation de la grid. desormais, le tableau s'affiche mais sans element malgré la présence de la meme chaine XML que pour la premiere partie.
aucune erreur de la part de firebug.
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
</style>
<script src="dojoroot_1.6/dojo/dojo.js" djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.XmlStore");
dojo.require("dojox.xml.parser");
dojo.ready
(
function()
{
hookXmlStore();
var myxml ="";
var args=
{
url:"sql.php",
handleAs:"json",
sync:true,
handle:function(data)
{
//alert(data);
myxml=data;
},
error:function(error)
{
alert(error);
},
content:
{
"action":"xml",
"request":"select * from film"
}
};
dojo.xhrGet(args);
var store = new my.data.XmlStringStore
(
{
xmlstring: myxml,
label: "description"
}
);
var layoutBooks=
[
[
{
field: "titre",
name: "Titre du Film",
width: 'auto'
},
{
field: "style",
name: "Style",
width: 'auto'
},
{
field: "resume",
name: "Resume",
width: 'auto'
},
{
field: "sortie",
name: "Annee",
width: 'auto'
},
{
field: "langue",
name: "Langue",
width: 'auto'
}
]
];
var grid4=new dojox.grid.DataGrid
(
{
store:store,
structure:layoutBooks,
query:
{
Title: '*'
},
clientSort: true,
rowSelector: '20px',
},
dojo.byId("gridContainer4")
);
// append the new grid to the div "gridContainer4":
//dojo.byId("gridContainer4").appendChild(grid4.domNode);
// Call startup, in order to render the grid:
grid4.startup();
}
);
hookXmlStore = function()
{
dojo.declare
(
"my.data.XmlStringStore",
[dojox.data.XmlStore],
{
constructor: function(args)
{
this.inherited("constructor", arguments);
this.xmlstring = args.xmlstring;
this.url = "dummy.xml";
},
_fetchItems: function(request, fetchHandler, errorHandler)
{
var url = this._getFetchUrl(request);
if (!url)
{
errorHandler(new Error("No URL specified."));
return;
}
var localRequest = (!this.sendQuery ? request : {});
var data = dojox.xml.parser.parse(this.xmlstring);
var items = this._getItems(data, localRequest);
if (items && items.length > 0)
{
fetchHandler(items, request);
}
else
{
fetchHandler([], request);
}
}
}
);
};
</script>
<style type="text/css">
@import "dojoroot_1.6/dojox/grid/resources/Grid.css";
@import "dojoroot_1.6/dojox/grid/resources/nihiloGrid.css";
@import "dojoroot_1.6/dijit/themes/claro/claro.css"
.dojoxGrid table { margin: 0; }
</style>
</head>
<body class=" claro ">
<div id="gridContainer4">
</div>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
dojo.addOnLoad(function() {
if (document.pub) {
document.pub();
}
});
</script>
</body>
</html> |
|