I, for the life of me, cannot find any information on how to use a returnred DataTable (from a Web Service) in JavaScript (from the "result" parameter in an OnComplete event handler). I am assuming the javascript object takes on the same form as the server-side
object, but nothing seems to be working. Can someone point me in the right direction or post some example code? Thank you very much!
The return result is an instance of client side Web.Data.DataTable type. The client type is significiently different than the server side counterpart. This is what the client type API looks like:
Man, I'm having a hard time just getting to my data. I'm going through the Atlas.js file and trying to figure out the properties of the Web.Data.DataTable object.
If I want to get the first column named "Name" from the first row, what methods do I use?
I've figured out that "result.getItem(0)" returns the first row, and "result.getColumn("Name")" returns the column object. But what do I do to get to the data of these two "intersections"? thanks!
No, on the server, you should return System.Data.DataTable in your webmethod. The converter is to translate a server System.Data.DataTable instance to a client Web.Data.DataTable type.
HTH,
Ting
This posting is provided "AS IS" with no warranties, and confers no rights.
I did, and that didn't work. Whenever I do get to an object and print it on screen, it prints as [Object object] rather than the actual data that should be in the column of that row. Know what I mean? Pain in the butt this is.
Besides, I think I have to use getRow and getColumn or whatever, I can't use indexes I don't think.
Can someone please give me some javascript code that works to access returned DataTable data.
jarrednichol...
Member
117 Points
25 Posts
Using returned DataTable in JavaScript
Feb 15, 2006 06:51 AM|LINK
Jarred
http://www.jarrednicholls.com/
tinghaoy
Participant
1140 Points
228 Posts
Microsoft
Re: Using returned DataTable in JavaScript
Feb 15, 2006 10:23 PM|LINK
The return result is an instance of client side Web.Data.DataTable type. The client type is significiently different than the server side counterpart. This is what the client type API looks like:
Web.Data.DataTable = function(columns, tableArray) {
this.get_columns = function()
this.get_keyNames = function()
this.get_isDirty = function()
this.get_length = function()
this.add = function(rowObject)
this.clear = function()
this.createRow = function()
this.getChanges = function()
this.getColumn = function(name)
this.getRow = function(index)
this.getItem = this.getRow;
this.remove = function(rowObject)
this.dispose = function()
this.getDescriptor = function()
this.initialize = function()
this.raiseCollectionChanged = function(action, changedItem)
this.raiseRowChanged = function(changedItem)
this.raisePropertyChanged = function(propertyName)
}
jarrednichol...
Member
117 Points
25 Posts
Re: Using returned DataTable in JavaScript
Feb 16, 2006 07:21 PM|LINK
You are awesome, thank you.
Jarred
P.S. From now on, I'll just look at the Atlas javascript and Atlas server-side methods :-)
P.S.S. Should I be returning a Web.Data.DataTable type on the server rather than a System.Data.DataTable? I assume yes :-)
http://www.jarrednicholls.com/
jarrednichol...
Member
117 Points
25 Posts
Re: Using returned DataTable in JavaScript
Feb 16, 2006 08:00 PM|LINK
Man, I'm having a hard time just getting to my data. I'm going through the Atlas.js file and trying to figure out the properties of the Web.Data.DataTable object.
If I want to get the first column named "Name" from the first row, what methods do I use?
I've figured out that "result.getItem(0)" returns the first row, and "result.getColumn("Name")" returns the column object. But what do I do to get to the data of these two "intersections"? thanks!
http://www.jarrednicholls.com/
tinghaoy
Participant
1140 Points
228 Posts
Microsoft
Re: Using returned DataTable in JavaScript
Feb 16, 2006 10:26 PM|LINK
No, on the server, you should return System.Data.DataTable in your webmethod. The converter is to translate a server System.Data.DataTable instance to a client Web.Data.DataTable type.
HTH,
Ting
Pavel Surmen...
Member
270 Points
54 Posts
Re: Using returned DataTable in JavaScript
Feb 27, 2006 06:21 PM|LINK
Pavel Surmenok
http://vbnet.ru/ - the leader among Russian Visual Basic sites
jarrednichol...
Member
117 Points
25 Posts
Re: Using returned DataTable in JavaScript
Mar 01, 2006 08:36 PM|LINK
I did, and that didn't work. Whenever I do get to an object and print it on screen, it prints as [Object object] rather than the actual data that should be in the column of that row. Know what I mean? Pain in the butt this is.
Besides, I think I have to use getRow and getColumn or whatever, I can't use indexes I don't think.
Can someone please give me some javascript code that works to access returned DataTable data.
Thanks much!
Jarred
http://www.jarrednicholls.com/
Garbin
Contributor
7428 Points
1507 Posts
ASPInsiders
Re: Using returned DataTable in JavaScript
Mar 05, 2006 01:57 PM|LINK
here's an example, code is commented. Hope it helps.
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Web.Services" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> [WebMethod] public DataTable GetDataTable() { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Name", typeof(string))); dt.Columns.Add(new DataColumn("LastName", typeof(string))); dt.Columns.Add(new DataColumn("Email", typeof(string))); dt.Rows.Add("John", "Doe", "john.doe@example.com"); dt.Rows.Add("Joe", "Smith", "jsmith@example.com"); return dt; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <atlas:ScriptManager ID="scriptManager" runat="server"></atlas:ScriptManager> <script type="text/javascript"> function getData() { PageMethods.GetDataTable(onGetComplete); } function onGetComplete(result) { var dataTable = result; // Get the number of rows. debug.trace(dataTable.get_length()); // Get row 0, property Name. debug.trace(dataTable.getItem(0).getProperty('Name')); // Get row 1, property Email. debug.trace(dataTable.getItem(0).getProperty('_rowObject').Email); // Add a new row. dataTable.add({Name:'Susan', LastName:'Jackson', Email:'sjack@example.com'}); // Update row 0, property Name. dataTable.getItem(0).setProperty('Name', 'Mary'); debug.trace(dataTable.getItem(0).getProperty('Name')); // Delete row 1. dataTable.remove(dataTable.getItem(1)); // Did we insert/update/delete any rows? debug.trace(dataTable.get_isDirty()); // Get the inserted/updated/deleted rows. var changes = dataTable.getChanges(); // How many rows did we insert/update/delete ? debug.trace(changes.inserted.length); debug.trace(changes.updated.length); debug.trace(changes.deleted.length); // Get the inserted rows. var inserted = dataTable.getChanges().inserted; // Ok, now clear the DataTable. dataTable.clear(); } </script> </form> <script type="text/xml-script"> <page> <components> <application load="getData" /> </components> </page> </script> </body> </html>Garbin
Contributor
7428 Points
1507 Posts
ASPInsiders
Re: Using returned DataTable in JavaScript
Mar 08, 2006 11:54 PM|LINK
I forgot to post the link to this article from my blog, where you can find a quick reference for the Web.Data.DataTable control.
kernelv12
Member
5 Points
1 Post
Re: Using returned DataTable in JavaScript
Mar 14, 2006 02:08 PM|LINK
This tool could also be helpful: http://www.wilcob.com/AtlasClassBrowser/
regards,
Kernel