i dont see anything in the documentation but i am trying to convert over code that is rendered in an html table over to jquery grid but the one missing piece is that many of the columns have images in them or other specialized html that i would like to show in the grid
To show an image in a grid row, this post has a nice summary:
Return the HTML element as your grid column's data. Do not use ' or " for the src, it will not work properly. The field should be like this:
<img src=../images/my_image.jpg>
This may not be the answer you're after, but DataTables will construct a grid from an HTML table. It features client side paging, sorting, filtering, client side editing and Ajax callback functions that will for server side paging.
With a table as your "source" you can have what ever you want in the columns.
$("#yourTableID").jqGrid({
url: '<%= ResolveUrl("ModelClass/ModelFunction")%>'
, datatype: "json"
, mtype: "POST"
, postData: { 'idofyourcolumn': $('#idofyourcolumn').val(),
'page': $('.pagedisplay').val(), 'rows': $('#rowCount').val()
}
, colNames: ['YOURHEADER', 'ACTION']
, colModel: [{ name: 'column1', index: 'column1name' },
{ name: 'action', index: 'action', width: 10, sortable: false, align: 'center'}]
, autoheight: true
, autowidth: true
, rowNum: 15
, rowList: [15, 20, 30, 50]
, pager: '#pager'
, sortname: 'column1'
, viewrecords: true
, sortorder: "desc"
, caption: "Sample Code"
, afterInsertRow: function (rowid, aData) {
jQuery('#yourTableID').setCell(rowid, 'action', '<img src="pathofyourimage/image.jpg" />');
}
, loadComplete: function () {
$('#ResultCount').text($("#yourTableID").getGridParam("records"));
}
})
.navGrid('#pager1'
, { search: true, refresh: false, view: false, del: false, add: false, edit: false }
, {} // default settings for edit
, {} // default settings for add
, {} // delete
, { closeOnEscape: true
, multipleSearch: true
, closeAfterSearch: true
} // search options
, {}
);
the key is in afterInsertRow: it contains your column image and data
If you want to add an image to a cell of a jqGrid, you have to use a hack, and if your datatype is 'client' it would work well.
- Set the image in a variable.
- var crossImg = "set you html src of image";
- Set the colmodel like this.
- {name:'delImage',index:'delImage', align:'center', width:40, editable:false,formatter: 'integer',formatoptions:{defaultValue:crossImg}}
© 2022 - 2024 — McMap. All rights reserved.