I'm having trouble figure out the proper way to get a sparkline graph rendering in a jqgrid cell and can't for the life of me find any relevant samples anywhere.
Anyway, after some research I decided the thing to do was try injecting the sparkline graph into the cell on afterRowInsert. Unfortunately I am doing it wrong. Here is what I am doing:
afterInsertRow: function(rowid, rowdata, rowelem) {
var cell = jQuery('#datapointlist').getCell(rowid, 'Graph');
$(cell).sparkline([1,34,3,2,1])
},
The contents of the cell on insertion is 'Loading' and after the event it remains unchanged. I'm not really even sure if this is the best way to try to get this working so if anyone can help me out it would be much appreciated.
I did't hear before about jQuery Sparkline, but simple search in Internet gives the answer. It seems to me the usage of the Plugin is very simple.
The first problem is from where we would get the data which we will show as sparkline. I placed the array like
[1,34,3,2,1]
which we will use to initialize the sparkline as a string in the column which will contain the lines at the end. So I placed"[1,34,3,2,1]"
in the corresponding cell. Then inside ofloadComplete
I get the cell contain convert it to the array with respect of jQuery.parseJSON and callsparkline
. As the result I received the following grid:You can see the grid live here.
Below you can find the code which I used: