[ 6 posts ]

Thomas Braun

  • Username: TommyB
  • Joined: Thu Aug 13, 2009 12:51 am
  • Posts: 7
  • Location: Germany
  • Offline
  • Profile
Tags:

scrollingDataTable always shows "no records found"

Post Posted: Tue May 18, 2010 5:42 am
+0-
Hi,

i'm using the following code to show a scrolling lookup table:

Code:
      function showPanel(obj){
        var myColumnDefs = [
            { key: "LASTNAME", label: "Last name" },
            { key: "FIRSTNAME", label: "First name" }
            ];

        var form = YAHOO.util.Dom.get('mainform');
        var datasource = "Some_URL";

        var xmlDataSource = new YAHOO.util.XHRDataSource(datasource);
        xmlDataSource.useXPath = false;
        xmlDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
        xmlDataSource.responseSchema = { resultNode: "record", fields: [ "LASTNAME", "FIRSTNAME" ] };

        var myDataTable = new YAHOO.widget.ScrollingDataTable("lookupPanel_bd", myColumnDefs, xmlDataSource);
        lookupPanel.show();

      }  // showPanel


The server a "Some_URL" returns the following XML data, but the table only shows "no record found":

Code:
<data>
  <record id="1">
    <FIRSTNAME>Thomas</FIRSTNAME>
    <LASTNAME>Braun</LASTNAME>
  </record>
</data>


What do I need to change to make it work?

regards
thomas

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: scrollingDataTable always shows "no records found"

Post Posted: Tue May 18, 2010 10:55 am
+0-
The XML data needs to have the <?xml .....> processing instruction as the very first thing, no spaces, no line feeds, to be recognized as XML by the browser. This happens before the xml reaches YUI and depends on the XML parser built-into the browser.

Also, it is not a good idea to render a datatable into a hidden container, it will often get the columns aligned wrong. You can call the onShow method to fix it or show the panel before rendering the table.

Thomas Braun

  • Username: TommyB
  • Joined: Thu Aug 13, 2009 12:51 am
  • Posts: 7
  • Location: Germany
  • Offline
  • Profile

Re: scrollingDataTable always shows "no records found"

Post Posted: Tue May 18, 2010 11:25 pm
+0-
Quote:
The XML data needs to have the <?xml .....> processing instruction as the very first thing, no spaces, no line feeds, to be recognized as XML by the browser.


I omitted this in my quote above - sorry.

I'm using Firefox+Firebug and Firebug shows the XML tab on the Network panel, so I'm quite sure the XML should be ok.

The complete reply looks like this:

Quote:
<?xml version="1.0" encoding="ISO-8859-1"?><data><record id="1"><ID>1</ID><FIRSTNAME>Thomas</FIRSTNAME><LASTNAME>Braun</LASTNAME></record></data>


And if the data wasn't ok, it would show "data error", not "no records found", I suppose?

Quote:
Also, it is not a good idea to render a datatable into a hidden container, it will often get the columns aligned wrong. You can call the onShow method to fix it or show the panel before rendering the table.


Not sure If I understand what you mean with that ?!?

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: scrollingDataTable always shows "no records found"

Post Posted: Wed May 19, 2010 7:44 am
+0-
Your XML and your responseSchema looks good to me, I can't imagine what might be going wrong.

You are correct, sorry, if it wasn't XML at all it would give a Data Error message.
The parseXMLData method uses getElementsByTagName to locate the records using the value passed in responseSchema.resultNode as its argument. If it cannot find any elements tagged <record> I believe it would return an empty array (actually a NodeList) but still an array so it would simply assume there are no record instances, not a data error.

So, I'm afraid I can't help you much unless you can place a working copy in some public place so I can run it with the debugger and see what's going on.

As for the last question, the scrolling datatable actually uses two HTML tables, one contains the headers and the other the data. To align the headers in one table with the columns in the other, it needs to actually read the widths of the columns to make the sizes of both match. Some browsers do not report size or position of elements not visible so DataTable cannot align the columns. If you show a table contained in a hidden container, the columns might be all misaligned with their headers.

Thomas Braun

  • Username: TommyB
  • Joined: Thu Aug 13, 2009 12:51 am
  • Posts: 7
  • Location: Germany
  • Offline
  • Profile

Re: scrollingDataTable always shows "no records found"

Post Posted: Fri May 21, 2010 6:07 am
+0-
Hi Satyam,

by using the debug version and stepping into the parseXMLData method myself I found the cause.

I had a mismatch between the content-type charset and the encoding in the <xml... processing instruction.

Now the actual data is found but only the first record one shows up. It is really hard to get ahead - but I won't give up :-)

Thomas Braun

  • Username: TommyB
  • Joined: Thu Aug 13, 2009 12:51 am
  • Posts: 7
  • Location: Germany
  • Offline
  • Profile

Re: scrollingDataTable always shows "no records found"

Post Posted: Tue May 25, 2010 1:39 am
+0-
Solved everything now - I had an additional error in the XML plus
did not set up the path to the datatable CSS correctly.

Now I need to get this working with pagination as I may have several hundred rows, which
takes waaaaaaay too long to GET from the server - let alone the rendering in the browser...
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum