• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2528
  • Last Modified:

An example of jqgrid-jquery sending data to spring controller?

Any example of sending data from jqGrid (either json or otherwise) to spring controller and sending the status back to the frontend will be much appriciated.

thanks
0
Amar-ms
Asked:
Amar-ms
  • 2
1 Solution
 
Sathish David Kumar NCommented:

var layoutOrders =
      [{
            cells:
            [[            
                      {
                       name: "<spring:message code="papa.rfq.rfqLine" />",
                        width: 8,
                        field:"rfqLine",
                        styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                                        
                },
                {
                      name: "<spring:message code="papa.rfq.ItemCode" />",
                         width: 10,
                    field: "itemCode",
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.Itemdesc" />",
                         width: 15,
                    field: "itemDesc",
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
               
               
                {
                      name: "<spring:message code="papa.rfq.qty" />",
                      width: 5,
                      editor: dojox.grid.editors.Input,        
                    field: "qty",
                               styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.uom" />",
                         width: 8,
                    field: "uom",
               
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.uprice" />",
                         width: 8,
                         editor: dojox.grid.editors.Input,
                    field: "uprice",
                    styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.currency" />",
                         width: 5,
                    field: "currency",
                   
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },

                {
                      name: "<spring:message code="papa.rfq.sd" />",
                         width: 11,
                    field: "sdate",
                 
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.ed" />",
                         width: 11,
                    field: "edate",
               
                      styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },

                {
                      name: "<spring:message code="papa.rfq.Total" />",
                         width: 8,
                    field: "total",
                                    styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.promiseDay" />",
                         width: 4,
                         editor: dojox.grid.editors.Input,
                    field: "pdays",
                    styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.comments" />",
                         width: 15,
                    field: "comments",
                   styles: 'height: 25px;text-align:center;color:#3e5c7f;'
                },
                {
                      name: "<spring:message code="papa.rfq.cancel" />",
                         width: 5,
                    field: "cancel",
                    editor:dojox.grid.editors.Bool
                      
                },
            ]]
      }, ];

      var itemData = {
     "items":[],      
     "identifier": "rfqLine"
    };

      
      var itemStore = new dojo.data.ItemFileReadStore({jsId: 'itemJson',data: itemData});
    var      ordersModel = new dojox.grid.data.DojoData(null,itemStore,{jsId: 'ordersModel', clientSort: true, query: {  rfqLine : '*' }});



this my grid define ...

below only i have sent the data to controller
function saveGridLines()
{		
	
var grid = dijit.byId('rfqQuote_gridTrack');
var str = '{"items" : [';
var rowCount = ordersModel.getRowCount();

var rfqId=document.getElementById('rfqId').value;
var supplierid=document.getElementById('supplierName').value;

	for( var i=0; i<rowCount; i++ )
			{	 				

		var rows  = ordersModel.getRow(i);		

		
				var temp = rows.comments;
				var comments;
				if(temp=='Enter your Comments here.')
				{
				comments="";	
				}
				else{
				comments=temp;
				}
				if(temp=='')
				{
					comments="";		
				}
				str += '{"rfqLine" :"'+rows.rfqLine+'",';																	
				str += '"itemCode" :"'+rows.itemCode+'",';					
				str += '"qty" :"'+rows.qty+'",';										
				str += '"uom" :"'+rows.uom+'",';
				str += '"uprice" :"'+rows.uprice+'",';
				str += '"currency" :"'+rows.currency+'",';
				str += '"sdate" :"'+rows.sdate+'",';
				str += '"edate" :"'+rows.edate+'",';
				str += '"total" :"'+rows.total +'",';
				str += '"pdays" :"'+rows.pdays+'",';					
				str += '"comments" :"'+rows.itemComments+'",';
				str += '"cancel" :"'+rows.cancel+'",';
							
				str += '}';
				if( i != (rowCount-1))
				{
					str += ',';
				}				
		}	
		
	
		str +=']}';	

	
		var jsonString = dojo.toJson(str, false);	
	dojo.xhrPost ({
	                 url: "rfqMainTain.htm?function=savegrid&rfqId="+rfqId+"&supplierid="+supplierid,
	                 form:"rfqForm",	  
	                 content:{"mytest":str},	                
	                 load: function (data, ioArgs){	  	                            
						papaGridData = {
					    "items":[],      
					    "identifier": "rfqLine"
					    };					    
	                  	try{	
	                  		
	                  		document.getElementById('grid_message').innerHTML = "<font color='green'><ol>Quote Value Saved Successfully  </ol></font>";
	                  		                  		
	                  	}catch(err){
	                  		console.debug(err);
	                  	}				                            	                  	
	                 	itemStore = new dojo.data.ItemFileReadStore({jsId: 'itemJson',data: itemData});
	                    ordersModel = new dojox.grid.data.DojoData(null,itemStore,{jsId: 'ordersModel', clientSort: true, query: {  rfqLine : '*' }});
	                  	dijit.byId('rfqQuote_gridTrack').setModel(ordersModel);
	                  	dijit.byId('rfqQuote_gridTrack').refresh();
	                
	                   },
	                   error: function (error) { 
	               		   document.getElementById('grid_message').innerHTML = 'Error Occured';	
	                   }
	            });		
	return true;
			
}

Open in new window

0
 
Sathish David Kumar NCommented:
Hi amar is this helpfull for u ???
0
 
Amar-msAuthor Commented:
looking for a jqgrid/jQuery
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now