The data that is coming as part of ajax call from my business class is as follows:
[{
"user_action": "<button class='detail-icon' title='Vehicle Pass History'onclick='javascript:openPopUpWagonList('DIM 008065');'> <img src='/WIMS/images/icon_detail.png'></button>",
"VEHICLE_ID": "DIM 008065",
"setFlag": "<img src='/WIMS/images/wims-tick.gif'>",
"clrFlag": "<img src='/WIMS/images/wims-tick.gif'>",
"setDate": "31 Jul 2010 11:11",
"lastClearDate": "24 Aug 2010 07:26",
"noOfdays": "24",
"ownerCode": "",
"operatorCode": "",
"maintainerCode": "",
"severity10Pass": "~",
"plot": "<button class='detail-icon' title='Plot' alt='Detail'onclick='javascript:popUpStepChangeListGraph('DIM 008065');'> <img src='/WIMS/images/icon_detail.png'></button>",
"activeFlag": "1"
}, {
"user_action": "<button class='detail-icon' title='Vehicle Pass History'onclick='javascript:openPopUpWagonList('N 005276');'> <img src='/WIMS/images/icon_detail.png'></button>",
"VEHICLE_ID": "N 005276",
"setFlag": "<img src='/WIMS/images/wims-tick.gif'>",
"clrFlag": "",
"setDate": "31 Aug 2011 10:05",
"lastClearDate": "24 Mar 2011 10:45",
"noOfdays": "0",
"ownerCode": "",
"operatorCode": "",
"maintainerCode": "",
"severity10Pass": "~~~",
"plot": "<button class='detail-icon' title='Plot' alt='Detail'onclick='javascript:popUpStepChangeListGraph('N 005276');'> <img src='/WIMS/images/icon_detail.png'></button>",
"activeFlag": "1"
}]
Here I have taken only 2 records for convenient readability, but I am displaying more than 150 records of this kind.
Now my ajax call format from my jsp page is as follows:
$.ajax({
type: "POST",
url: f_reqAction, // url is set already
data : {maintainer:maintainerValue,show:showValue},
dataType:'json',
async: true, /* If set to non-async, browser shows page as "Loading.."*/
cache: false,
timeout:80000, /* Timeout in ms */
success: handleApplyEventResponse,
error: handleResponseError
});
function handleApplyEventResponse(response) {
// response is coming from my business class
$("#stepChangeData").jqGrid('clearGridData');
if(response.length > 0){
for(var i=0;i<response.length;i++){
jQuery("#stepChangeData").jqGrid('addRowData',i+1,response[i]);
}
$('#stepChangeData').setGridParam({rowNum:response.length});
}
}
When I want to remove the data by calling jQuery("#gridtabID").jqGrid('clearGridData');
a javascript error is coming prompting to stop running the script. but if the data size is small like 20 or 30 the problem does not come.
I understand populating response data by calling jqGrid('addRowData'
inside for loop is not efficient when the data is this much large. but i could not find a jqgrid api which can add this response data directly in the grid without any looping.
And i could not create the buttons contained in my json data through formatter option of colModel
as I found it extremely difficult to create that type of button by formatter.So I created it in my business ligic and sending it to jsp page with json data as part of the ajax respose.
So in the above context, I would have loved to have an api which could have set this json data into the grid at a shot (i.e without any looping). And I think this way this script problem could have been averted as well.