jqgrid在列中显示图片
<script>
$(function () {
showEmp();
})
function showEmp() {
$('#bookTable').empty();
var img;
function alarmFormatter(cellvalue, options, rowdata) {
return ' <img src="'+cellvalue+'" id="img' + rowdata.Id + '" style="width:50px;height:50px;" />';
}
$('#imgDialog').hide();
$('#bookTable').jqGrid({
styleUI:'Bootstrap',
url:'/product/findAll',
datatype:'json',
colNames:['ID','Name','Picture','Price','Buy'],
cellEdit:true,
editurl:'/product/operProduct',
colModel:[
{name:'id',align:'center'},
{name:'productName',align:'center',editable:true},
{ name: 'picpath', index: 'dsource_alarm', width: 100, align: "center", sortable: false, editable: false, formatter: alarmFormatter },
{name:'price',align:'center',editable:true},
{name:'operation',align:'center',
formatter:function (value,options,row) {
return '<input class="btn btn-info" οnclick=buyBook("'+row.id+'") type="button" value="购买">';
}
},
],
autowidth:true,
pager:'#bookpager',
rowList:[2,5,10,15,20,50],
rowNum:2,
page:1,
viewrecords:true,
multiselect:true,
rownumbers:true,
height:350,
gridComplete: function () {
$('#gridTable img').hover(function (e) {
$("body").append("<div id='preview'><img src='" + this.src + "' alt='Image preview'/></div>");
$("#preview")
.css("top", (e.pageY) + "px")
.css("left", (e.pageX) + "px")
.fadeIn("fast");
}
, function () {
$("#preview").remove();
}).click(function () {
$('#imgDialog img').attr('src', this.src);
$('#imgDialog').dialog({
autoOpen: true,
buttons: { "Ok": function () { $(this).dialog("close"); }, "Close": function () { $(this).dialog("close"); } },
draggable: true,
resizable: false,
bgiframe: true
});
img = this;
});
}
}).navGrid('#bookpager');
};
</script>