jqgrid在列中显示图片

本文详细介绍了如何在jqGrid中自定义列格式以显示图片,包括图片预览和对话框弹出功能的实现,适用于前端开发人员学习和参考。
jqgrid在列中显示图片
<script>
    $(function () {
        showEmp();
    })
    function showEmp() {
        //清空书单table
        $('#bookTable').empty();
        var img;
        //自定义图片的格式,可以根据rowdata自定义
        function alarmFormatter(cellvalue, options, rowdata) {
            return ' <img src="'+cellvalue+'" id="img' + rowdata.Id + '"  style="width:50px;height:50px;" />';
        }
            $('#imgDialog').hide();
        //展示图书信息
        // 初始化数据表格
        $('#bookTable').jqGrid({
            // 整合使用bootstrap样式的属性
            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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值