Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Change Datasource for Datatable   Message List  
Reply | Forward Message #30635 of 52127 |
I just posted this in the YUI group but it doesn't look like that
group gets used much.
------
I would like to try to use one datasource for the YUI datatable such as
an array for the initial load of a page, then use Json over xhr for
subsequent table events such as sorting and paging. Has anyone here
done this or have suggestions on how to do it?

Here is something I tried, but doesn't seem to work, it uses 2 arrays,
but the concept is the same.

<html>
<head>
<title>Datatable Test</title>
<link type="text/css" rel="stylesheet"
href="http://yui.yahooapis.com/2.5.1/build/datatable/assets/skins/sam/datatable.\
css
">

<script type="text/javascript"
src="http://yui.yahooapis.com/2.5.1/build/yahoo-dom-event/yahoo-dom-event.js"></\
script>

<script type="text/javascript"
src="http://yui.yahooapis.com/2.5.1/build/element/element-beta-min.js"></script>

<script type="text/javascript"
src="http://yui.yahooapis.com/2.5.1/build/datasource/datasource-beta-min.js"></s\
cript>

<script type="text/javascript"
src="http://yui.yahooapis.com/2.5.1/build/connection/connection-min.js"></script\
>

<script type="text/javascript"
src="http://yui.yahooapis.com/2.5.1/build/datatable/datatable-beta-min.js"></scr\
ipt>

</head>



<body class='yui-skin-sam'>

<button id='button'>button</button>
<div id='yuidt'></div>

</body>


<script type='text/javascript'>
YAHOO.example.Data = {
bookorders: [
{id:"po-0167", date:new Date(1980, 2, 24), quantity:1,
amount:4, title:"A Book About Nothing"},
{id:"po-0783", date:new Date("January 3, 1983"),
quantity:null, amount:12.12345, title:"The Meaning of Life"},
{id:"po-0297", date:new Date(1978, 11, 12), quantity:12,
amount:1.25, title:"This Book Was Meant to Be Read Aloud"},
{id:"po-1482", date:new Date("March 11, 1985"), quantity:6,
amount:3.5, title:"Read Me Twice"}
]
}

YAHOO.example.Data2 = {
bookorders: [
{id:"po-1111", date:new Date(1980, 2, 24), quantity:1,
amount:4, title:"A Book About Nothing"},
{id:"po-2222", date:new Date("January 3, 1983"),
quantity:null, amount:12.12345, title:"The Meaning of Life"},
{id:"po-3333", date:new Date(1978, 11, 12), quantity:12,
amount:1.25, title:"This Book Was Meant to Be Read Aloud"},
{id:"po-4444", date:new Date("March 11, 1985"), quantity:6,
amount:3.5, title:"Read Me Twice"}
]
}

YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.Basic = new function() {
var myColumnDefs = [
{key:"id", sortable:true, resizeable:true},
{key:"date", formatter:YAHOO.widget.DataTable.formatDate,
sortable:true,
sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC},resizeable:true},

{key:"quantity",
formatter:YAHOO.widget.DataTable.formatNumber, sortable:true,
resizeable:true},
{key:"amount",
formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true,
resizeable:true},
{key:"title", sortable:true, resizeable:true}
];

this.myDataSource = new
YAHOO.util.DataSource(YAHOO.example.Data2.bookorders);
this.myDataSource.responseType =
YAHOO.util.DataSource.TYPE_JSARRAY;
this.myDataSource.responseSchema = {
fields: ["id","date","quantity","amount","title"]
};
this.myDataTable = new YAHOO.widget.DataTable("yuidt",
myColumnDefs, this.myDataSource, {caption:"DataTable
Caption"});



this.myDataSource2 = new
YAHOO.util.DataSource(YAHOO.example.Data2.bookorders);
this.myDataSource2.responseType =
YAHOO.util.DataSource.TYPE_JSARRAY;
this.myDataSource2.responseSchema = {
fields: ["id","date","quantity","amount","title"]
};



YAHOO.util.Event.addListener("button", "click", function(){new
YAHOO.widget.DataTable("yuidt",
myColumnDefs, this.myDataSource2, {caption:"DataTable
Caption"}); });
};
});
</script>
</html>




Fri May 9, 2008 1:21 pm

fblb
Offline Offline
Send Email Send Email

Forward
Message #30635 of 52127 |
Expand Messages Author Sort by Date

I just posted this in the YUI group but it doesn't look like that group gets used much. ... I would like to try to use one datasource for the YUI datatable...
Jim
fblb
Offline Send Email
May 9, 2008
1:21 pm

To switch to an XHR DataSource, you might try something like the following, I guess it should work but I haven't tested it: var ds =...
Satyam
satyamutsa
Offline Send Email
May 9, 2008
4:27 pm

Thank you Satyam, I was able to get Datatable to change sources between two js arrays, next I will implement the change to an xhr request. ... following, ... ...
Jim
fblb
Offline Send Email
May 12, 2008
2:29 pm

setting ds.liveData = "myDataServer.php"; from some reason it results in a request being made to /myDataServer.phpnull ... following, ... for the ... match ......
Jim
fblb
Offline Send Email
May 12, 2008
2:49 pm

Just needed to add an initialRequest. So it is somewhat working, data comes in from the xhr request but the table only renders 1 row, when there are 3 rows of...
Jim
fblb
Offline Send Email
May 12, 2008
3:09 pm

Just an error in the json output from my php script. Here is the code if you are interested: <html> <head> <title>Datatable Test</title> <link type="text/css"...
Jim
fblb
Offline Send Email
May 12, 2008
3:14 pm

I just implemented this, switching from a LocalDataSource for the initial page load to an XHRDataSource for server side sorting. I was able to do it without...
anjhinz
Offline Send Email
Jul 2, 2009
7:57 pm

It is better to do on the initEvent since the initEvent fires just once while renderEvent fires every time the DataTable is redrawn no matter what the reason. ...
Satyam
satyamutsa
Offline Send Email
Jul 2, 2009
8:26 pm

That is a reported bug. You have to either add a ? at the end of the url so that it will produce: /myDataServer.php?null so the browser can tell where the...
Satyam
satyamutsa
Offline Send Email
May 12, 2008
6:16 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help