Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82121

Iterating a JSON Object and displaying Datatable

$
0
0
i have an HTML form with muliple user inputs and a submit button. I need to pass the parameters selected to a Servlet and then search the
resultset with the input parameters and then construct a datatable without page refresh.

I was able to complete the data retrieval part . Create the JSP form , invoke the Servlet by using Jquery but i am not able to create the datatable with the server data.

I am getting List<PackOutRqstData > from the Server . but right now i need to only display requestHeader on the Table.

 
public class PackOutRqstData implements Serializable
{	
	private VwPackOutRqstSum requestHeader = null;
	private List<PackOutRqstItm> requestDetail = null;
}

public class VwPackOutRqstSum implements Serializable {	

    private BigDecimal packOutRqstGid;
    private Date rqstTms;
    private BigDecimal fromStorNum;    
    private String usrId;    
    private BigDecimal ttlRqstQty;    
    private BigDecimal ttlMovedQty;    
    private BigDecimal packOutSttsCdGid;
}

public class PackOutRqstItm implements Serializable{

    private BigDecimal packOutRqstItmGid;
    private BigDecimal packOutRqstGid;
    private String itmNum;
    private BigDecimal rqstQty;
    private BigDecimal movedQty;
    private BigDecimal dstrnNum;
    private BigDecimal packOutSttsCdGid;
    private BigDecimal packOutReasnCdGid;
    private Date insrtTms;
    private String insrtPgmNam;
    private Date lastUpdTms;
    private String lastUpdPgmNam;	
	}


Java Script
 

 $('#example').dataTable();
    "sScrollY"; "200px",
	"bPaginate"; true;

$("#submit").click(function blabla() {
       var formData = $('form').serialize();
       $.ajax( {
    	   type: "POST",
           url: "SearchServlet",
           data: formData,
           dataType: "json",
    	    success: function(data) {
    	              // Not Sure how to build the table from JSON

    	    }
    	 });
 

The HTMLresult table
 <table id="example" class="display">
		 <thead>
			<tr>
				<th align="left">Packout Request #</th>
				<th align="left">Requested Date</th>
				<th align="left">From</th>
				<th align="left">SKU</th>
				<th align="left">QTY Requested</th>
				<th align="left">QTY Moved</th>
				<th align="left">Reason Code</th>
				<th align="left">Status</th>
			</tr>
		</thead> 
		<tbody >


		</tbody>
	</table> 

Servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		response.setHeader("Cache-control", "no-cache, no-store");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Expires", "-1");

		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		response.setHeader("Access-Control-Allow-Headers", "Content-Type");
		response.setHeader("Access-Control-Max-Age", "86400");
		
		
		String code = (String) request.getParameter("code");
		System.out.println("***** "+ code);
		String fromDate = (String) request.getParameter("fromDate");
		System.out.println("***** "+ fromDate);		
		String toDate = (String) request.getParameter("toDate");
		System.out.println("***** "+ toDate);
		String output = "Code "+ code+ " From Date "+fromDate + " to date "+toDate;
		System.out.println(output);

		Gson gson = new Gson();
		JsonObject myObj = new JsonObject();


		List<PackOutRqstData> packOutRqstDatas = DataRepository
				.getPackoutRequestData(null);

		JsonElement jsonObject = gson.toJsonTree(packOutRqstDatas);
		
		if (jsonObject == null) {
			myObj.addProperty("success", false);
		} else {
			myObj.addProperty("success", true);
		}
		myObj.add("jsonObject", jsonObject);
		out.println(myObj.toString());
		out.close();
	
	}
 


JSON Object for reference
 
[{"requestHeader":{"packOutRqstGid":123456,"rqstTms":"Dec 3, 2012 11:35:17 PM","fromStorNum":555,"usrId":"ivin","ttlRqstQty":100,"ttlMovedQty":50,"packOutSttsCdGid":1},"requestDetail":[{"packOutRqstItmGid":1,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"},{"packOutRqstItmGid":2,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"}]},{"requestHeader":{"packOutRqstGid":654321,"rqstTms":"Dec 3, 2012 11:35:17 PM","fromStorNum":444,"usrId":"ivin","ttlRqstQty":100,"ttlMovedQty":50,"packOutSttsCdGid":1},"requestDetail":[{"packOutRqstItmGid":3,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"},{"packOutRqstItmGid":4,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"}]}]

Viewing all articles
Browse latest Browse all 82121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>