I'm having a result
inside which there are 5 items. Now under certain conditions i have to push those items in an array and bind it in jqgrid as columns and rows. So i have to loop into the result(something like that). How can i do?
//Code:
var colname = [];
var colHeader = [];
$.ajax({
url: '@(Url.Action("LoadColumns", "Home"))',
datatype: 'json',
mtype: 'GET',
success: OnComplete,
error: OnFail
});
function OnComplete(result) {
var i = 0;
$.each(result, function () {
console.log(result.rows[i]);
var currentRow = result.rows[i];
colHeader.push(currentRow.Name);
// alert(currentRow.Name);
switch (currentRow.Datatype) {
case 'int':
colname.push({ name: currentRow.Name, index: currentRow.Name, width: 200, align: 'left', sortable: true, editable: false, sorttype: 'int' });
break;
case 'String':
colname.push({ name: currentRow.Name, index: currentRow.Name, width: 200, align: 'left', sortable: true, editable: true });
break;
case 'DateTime':
colname.push({
name: currentRow.Name, index: currentRow.Name, width: 200, align: 'left', sortable: true, editable: true, sorttype: 'date',
formatter: 'date', formatoptions: { newformat: 'm-d-Y' }, datefmt: 'm-d-Y'
});
break;
case 'dropdown':
if (currentRow.ValueList != null && currentRow.ValueList != '') {
var ValueListArray = currentRow.ValueList.split(" ");
var valueListItems = '';
$.each(ValueListArray, function (index, values) {
valueListItems = valueListItems + values + ":" + values + ";";
});
}
colname.push({
name: currentRow.Name, index: currentRow.Name, width: 200, edittype: "select", formatter: 'select',
editoptions: { value: valueListItems.slice(0, -1) }, stype: 'select'
, searchoptions: { value: ':All;' + valueListItems.slice(0, -1) }, align: 'left', sortable: true, editable: true
});
break;
}
i++;
});
}
when i tried i'm getting only one value getting printed for 11 times.
Not sure where i'm wrong? Kindly help.