Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to send the vendorData array to your initVendorTable function. You'll have to edit the function definition for it to receive this data as a parameter. Also, from the looks of it, you're leaking globals, which is giving you unexpected results. Use the <code>var</code> keyword whenever you define variables to prevent this.</p> <p>This is my best attempt at a fix: </p> <pre><code>function getVendors() { $.ajax({ async : true, type : "GET", url : "/JavaTestService/rs/TestService/getMVendors?version=2", dataType : "json", success : function(json) { // initialize vendorData to empty array // var keeps this variable local var vendorData = []; $.each(json.resultSet.merchandiseVendor, function(index, item){ // add element to vendorData vendorData.push({ "name": item.name, "number": item.number }); }); // send the constructed array to the initVendorTable function initVendorTable(vendorData); }, error : function(xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); } </code></pre> <p>And here's the new definition for the initVendorTable function:</p> <pre><code>/* * Initialize the table containing the list of vendors * vendorData is the array of data to process */ function initVendorTable(vendorData) { jQuery("#supplierTable").jqGrid({ datatype : "local", height : 250, colNames : [ 'Vendor Number', 'Vendor Name' ], colModel : [ { name : 'number', index : 'name', width : 200, sorttype : "int" }, { name : 'name', index : 'number', width : 200 } ], rowNum : 10, rowList : [ 10, 20, 30 ], sortname : 'number', viewrecords : true, sortorder : "desc", caption : "Suppliers" }); for(var i=0;i&lt;=vendorData.length;i++){ $("#supplierTable").jqGrid("addRowData",i+1,vendorData[i]); } alert(vendorData); } </code></pre> <p>I'm assuming your usage of the jqGrid plugin is accurate, because I'm not familiar with how it works. </p> <p>I hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload