Search code examples
ajaxjsonyuiyui-datatable

yui datatable error


I have a problem with json data insertion in my DataTable. Here an example of json data send by server:

{"geneItemList":"{"col":"symbol","qv":"cd4","limit":"-1","start":"0","geneid":"920","name":"CD4"
,"symbol":"CD4","lastupdated":"2009-05-20 10:01:52.0","lastmodified":"2009-05-20 11:12:37.0"}
,...

And here my YUI code:

 <script type="text/javascript">
    YAHOO.namespace("local");
    var qct = YAHOO.local;


        YAHOO.util.Event.addListener(window, "load", function() {
            qct.RowSelection = function() {
                var myColumnDefs = [
                    {key:"geneid", label:"Gene", formatter: "number", sortable:true},
                    {key:"name", label:"Name", sortable:true},
                    {key:"symbol", label:"Symbol", sortable:true},
                    {key:"lastupdated", label:"Last Updated", formatter:"date", sortable:true},
                    {key:"lastmodified", label:"Last Modified", formatter:"date", sortable:true}
                ];

                var myDataSource = new YAHOO.util.DataSource("qct-list.html");
                myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
                myDataSource.connXhrMode = "queueRequests";
                myDataSource.responseSchema = {
                    resultsList: "geneItemList",
                    fields: [{key:"col", parser:"string"},
                             {key:"qv", parser:"string"},
                             {key:"limit", parser:"number"},
                             {key:"start", parser:"number"},
                             {key:"geneid", parser:"number"},
                             {key:"name", parser:"string"},
                             {key:"symbol", parser:"string"},
                             {key:"lastupdated", parser:"date"},
                             {key:"lastmodified", parser:"date"}]
                };

                // test this
                var myGeneListTable = new YAHOO.widget.DataTable("geneListTable", myColumnDefs, myDataSource,
                {initialRequest:"?col=<c:out value="${fieldName}"/>&qv=<c:out value="${queryValue}"/>&start=<c:out value="${start}"/>&limit=<c:out value="${limit}"/>", selectionMode:"single"});
etc...

When I test my page, I have "Data error." in my datatable!

An idea what is wrong?


Solution

  • I found the solution to my problem. It was a mistake to json!

    Bad :

    {"geneItemList":"{"col":"symbol","qv":"cd4","limit":"-1","start":"0","geneid":"920","name":"CD4"
    ,"symbol":"CD4","lastupdated":"2009-05-20 10:01:52.0","lastmodified":"2009-05-20 11:12:37.0"}
    ,...
    

    Good :

    {"geneItemList":**[**{"col":"symbol","qv":"cd4","limit":"-1","start":"0","geneid":"920","name":"CD4"
    ,"symbol":"CD4","lastupdated":"2009-05-20 10:01:52.0","lastmodified":"2009-05-20 11:12:37.0"}
    ,...}**]**
    }
    

    It was just a syntax problem! If you have a "data error" with YUI DataTable, the first thing to do is look at the JSON response from the server.