aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How do I update table using postJSON Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How do I update table using postJSON" Watch "How do I update table using postJSON" New topic
Author

How do I update table using postJSON

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183

Does anyone has code snippets for updating tables using postJSON


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Why would you use postJSON for such a task? And, you haven't really said anything about what you are trying to do or what problems you are having. Also, please do not post JSP markup in an HTML forum -- it's meaningless in this context.

Please put as much effort into making your posts as you would like people to take in answering them.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
My technology stack consists of Spring MVC 3.0 and it has a lot of support for postJSON. I have used a combination of jQuery/postJSON for some transactions like displaying combobox downdrop values and such.

Using the same wiring I was able to load data from the server into the client for loaded my jQuery datatable which already has preloaded data but I was unable to update the Spring items in the table and refreshing the table with new values.

Sorry about the jsp code fragments here. It was just to show where I was planning to use the javascript code. I can post this in the jsp forum if it makes more sense there.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

No. If it's a client side issue, it should be posted here, but with the generated client-side HTML. JavaScript doesn't know anything about the JSP markup.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Jay Abrahm wrote:My technology stack consists of Spring MVC 3.0 and it has a lot of support for postJSON. I have used a combination of jQuery/postJSON for some transactions like displaying combobox downdrop values and such.


Just because there is a lot of support for something, doesn't mean you should go out of your way to use it. Using postJSON for something like select values (HTML has no such thing as a dropdown) makes sense. Simple key/value pairs of data. But for something more complex, like a table, it is a lot easier to return HTML fragments. For example, on an application I am working on I have a table...



I issue an Ajax request to the server where my controller simply forwards the request to the JSP that renders my table row:



Then I just use the jQuery's append() method to add it to my TBODY element. Really simple and zero manual processing of data on the client. If you're needs a more complex then I highly recommend something like jqGrid.


GenRocket - Experts at Building Test Data
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
@ Gregg Bolinger -- Thanks, I did just that. jQuery build up html fragments. I just need to clear up some bugs in the code and I should be all good.




1. After adding new rows the html table is no longer recognized as a data table.
2. If I duplicate the datatable initialization code, I get a error message that it is already initialized.
3. I need to add logic to add new rows (which I dont think is too difficult)

Thanks


Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ahhhh, new information. Are you using a dataTable plugin? If so, then absolutely adding rows to it might make it not work. The plugin should have a means for you to add rows through it's API. If it doesn't then you need to find a better plugin.
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Its not that I withheld info :-). I just started using it then since it had a feature that I was looking for (a slick search on table data).

Mostly, javascript is all about looking in the right direction. I tried to persist with using the html fragments but you were right I had to use the API to add rows....

Thanks again Gregg .... It all looks good !!

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I update table using postJSON