views:

381

answers:

2

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 !!!

A: 

If you don't get an answer on StackOverflow, you may want to try posting your question to the YUI developer forums: http://yuilibrary.com/forum. Many YUI experts, including the most experienced DataTable developers, hang out there.

-Eric

Eric Miraglia
@Eric Miraglia Good job at YUI Team. Although i heavily use YUI widgets, your "answer" sounds like a comment. See my job about **single and dual-click** by using YUI DATATABLE http://jsbin.com/ideha It works fine
Arthur Ronald F D Garcia
+1  A: 

changing to TYPE_JSARRAY solved the problem...

Thanks for your comments Eric ! I went to this forum and it is indeed the place for datatable questions.

oimoim