Jump to content

Get data into XML to pass back to server?


ober
 Share

Recommended Posts

So, I spent the past few hours implementing this great EXTJS editor grid: http://www.extjs.com/deploy/dev/examples/grid/edit-grid.html

 

I wrote a routine to pull data out of the database (MSSQL) and dump it to XML so this grid could read and display it.  And then I realize that I somehow have to figure out how to get the data BACK INTO the database.  Since I can't write the data to anything and store that back to the server using JS... how the hell am I supposed to use this thing?  Have I just wasted several hours of research and coding??

 

I guess one approach would be sending all the data back via AJAX, but there has to be a cleaner approach, right?

 

Has anyone dealt with this?

Link to comment
Share on other sites

I usually iterate thtough store records, and add them one by one to an array. Then use Ext.util.JSON.encode to make JSON string out of it.

 

Other way to do it, is to hook into 'afteredit' listener of the EditorGrid and send each changed value to the server right after user accepts the changes in given field.

Link to comment
Share on other sites

Sure:

 

var data = new Array();
SomeGrid.store.each(function(record)) {
  data.push(record.data);
}
var dataJson = Ext.util.JSON.encode(data);
Ext.Ajax.request({
  url: 'some.url',
  params: {
    data: dataJson
  }
})

 

There's probably a better way to do it, but this works fine.

Link to comment
Share on other sites

I have a webpage that has tons of data as well.... best way i found to edit data or save data is to do it though javascript.  Javascript greatly reduced the code on the page, the reason why is the only function i had was

 

<tr><td><input type=button value='Save' onclick="save_data(this);">

 

I hope you know what ( this ) is, is so read up on it.  This will result in an elementObject of the input field.  But use your nodes.  elementObject.parentNode.parentNode.  alert the results of the elementObject that results for each part and stop at the HTML - TR node.  After that you can evaluate data each INPUT field or TD field within the TR element.  If your understanding why im suggesting this you might find it useful in processing your data back into a AJAX thingy.

 

Personally i would loop each input field into a query string and send that string back to a page that is just meant to recieve data.  However you can use the CURRENT page to recieve the data.  HOW?  Well in PHP you divid your page.  1 page would be recieving POST/GET request.  Another would be the output of the normal page which is ur current page.  From what i see your good enough with ajax/css/probably php and a few other languages to figure out what solution you need and how to make it work.  I hope something here helped.

Link to comment
Share on other sites

Yeah, I've done the whole AJAX thing and I don't have any issues there.  My only new issue is that I've never dealt with one of these grids and I don't know how the data is stored or read or retrieved after updating.  I'll play around with what Mchl posted and see what I can do with it.  Honestly, this is a lot of work when I probably could have created this interface with pure PHP a lot faster... but I want the end user experience to be good so I'm trying to go above and beyond.

Link to comment
Share on other sites

ExtJS makes a lot of sense once you understand how it's built.

Grid has a Store, Store is a collection of Records, Records represent individual rows.

 

I can recommend you a really good book, if you're planning to do some more work with Ext.

Here's a free chapter with some basic information: http://www.manning.com/garcia/Garcia_MEAPCH1.pdf.pdf

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.