Monday, September 3, 2007

.Net Web Service with Ext data store

After using Ajaxpro with a couple of applications, I thought I should look into a more standardized approach for Ext/.Net integration. Specifically, how to bind SQL data on the server to a Ext data store. Ajaxpro's future seems uncertain.

First the Web Service:

[WebMethod]
public XmlDocument getSites(String Site, String Type, String Disc, String Manu, String query, String limit, String start, String callback)
{

XmlDocument xmlDoc = new XmlDocument();
DataSet ds = new DataSet();
String sql = " Select SITE as col1 from mytable where site = " + Site;

// create a connection
SqlDataAdapter oda = new SqlDataAdapter(sql, connStringSQL);
oda.Fill(ds);
xmlDoc.LoadXml(ds.GetXml());
return xmlDoc;
}
And the Ext code, with the .Net xml doc having 'Table' as record:

// parameters that get passed
var inparms ={query: '', start: '', limit: '', callback: '', Site: '', Type: '', Disc: '', Manu: ''};

var xmlread = new Ext.data.XmlReader({ record: 'Table' }, [
// set up the fields mapping into the xml doc
{name: 'col1'} ]);

// create the Data Store
var dsSites = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({method:'POST',url: 'Service.asmx/getSites'}),
reader: xmlread, params: inparms });
.
.
.
dsSites.load( { params : inparms});
or
dsSites.load( {params : {query: '', start: '', limit: '', callback: '', Site: 'London', Type: '', Disc: '', Manu: ''});

2 comments:

Vladimir Chernya said...

Andy - what you do is great
I am searching for similar samples
and found none.
Do you have examples of updaing grid after initial loading
Thanks,
Vlad

amackay99@gmail.com said...

My next post takes an Ext Dataset and sends it to the server for update. This dataset could easily belong to an Ext Editorgrid that is updated by the user who then hits a 'save' button.