Hi, I don't understand what I'm doing wrong here ! I keep getting a Data Error. But I validated the JSON and it's ok...
Here is the javascript from the YUI Datatble example (slightly modified).
<pre class="prettyprint"><code>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
//var Ex = YAHOO.namespace('example');
var dataSource = new YAHOO.util.DataSource("jsondb/json_meta_proxy.html",{
responseType : YAHOO.util.DataSource.TYPE_JSON,
responseSchema : {
resultsList: "records",
fields: [
{key:"idprojet"},
{key:"nomprojet"}
],
metaFields: {
totalRecords: "totalRecords"
}
},
doBeforeCallback : function (req,raw,res,cb) {
// This is the filter function
var data = res.results || [],
filtered = [],
i,l;
if (req) {
req = req.toLowerCase();
for (i = 0, l = data.length; i < l; ++i) {
if (!data[i].state.toLowerCase().indexOf(req)) {
filtered.push(data[i]);
}
}
res.results = filtered;
}
return res;
}
});
var cols = [
{key:"idprojet"},
{key:"nomprojet"}
];
var paginateur = new YAHOO.widget.Paginator({
rowsPerPage : 25,
pageLinks : 10
});
var conf = {
paginator : paginateur,
sortedBy: {key:'idprojet', dir:YAHOO.widget.DataTable.CLASS_ASC}
};
var dataTable = new YAHOO.widget.DataTable('tbl',cols,dataSource,conf);
var filterTimeout = null;
var updateFilter = function () {
// Reset timeout
filterTimeout = null;
// Reset sort
var state = dataTable.getState();
state.sortedBy = {key:'idprojet', dir:YAHOO.widget.DataTable.CLASS_ASC};
// Get filtered data
dataSource.sendRequest(YAHOO.util.Dom.get('filter').value,{
success : dataTable.onDataReturnInitializeTable,
failure : dataTable.onDataReturnInitializeTable,
scope : dataTable,
argument: idprojet
});
};
YAHOO.util.Event.on('filter','keyup',function (e) {
clearTimeout(filterTimeout);
setTimeout(updateFilter,600);
});
});
</script>
and here is the JSON data in the file "jsondb/json_meta_proxy.html"
{
"recordsReturned": 1,
"totalRecords": 1,
"startIndex": 0,
"sort": "idprojet",
"dir": "asc",
"records": [
{
"idprojet": "11256",
"nomprojet": ""
}
]
}
Many thanks for your help !!!