I want to display a small image in the first column of jqgrid for all data I get from DB.
jquery("#tableName").jqgrid({
.....
colNames : ['', ''],
colModel : [{
width : '25%',
},{
name : 'someValue',
index : 'somevalue',
widht : '75%',
sorttype: 'text'
}]
});
I want to add an image in the first colmodel. i tried formatter, but not sure about cellvalue, row object, options. Any help would be appreciated.
I did something like this for image
function imageFormat( cellvalue, options, rowObject ){
return '<img src="'+cellvalue+'" />';
}
Where should i give the image src ? how to mention the imageformat in the colmodel ?
Thanks
You can move the image through xml or json in your url parameter like this:
note that < is
<
Look this example :)
You can see the complete example here: http://jsfiddle.net/tabalinas/ccy9u7pa/16/
If you need to set image in for example the first column of the grid you can define the grid
The
formatter
need just return a string which is HTML fragment which need be placed in the column. Because all parameters in JavaScript are optional and we need no then we can defineformatter
as function without parameters. The propertywidth
is the size of column in pixel. If you use other jqGrid options likeautowidth: true
or specify the whole width of the grid with respect ofwidth
option (and if you don't useshrinkToFit: false
option) then jqGrid will scale the column width based on the value ofwidth
property of the column incolModel
. To have no scaling of the column with the image I includedfixed: true
property additionally.Some common remark: you should be careful with case of names in JavaScript. For example the first line of code which you posted (
jquery("#tableName").jqgrid({
) should be replaced withjQuery("#tableName").jqGrid({
.