EasyUI,TopJUI的datagrid显示图片并点击放大浏览

TopJUI是对EasyUI的封装,本质其实是一样的,本文以TopJUI为例,有问题可以下方留言,看到会回复,一起学习,共同进步。话不多说,直接源码。

1.静态页面,datagrid是动态创建的

  1. js,动态创建复合表头
var url = '@Url.Action("LoadPlanInspectionListQuestionDatagridInfo", "Inspection")';
        $("#PlanInspectionQuestionListInfo").iDatagrid({
            fit: true,
            fitColumns: true,
            method: 'GET',
            url: url,
            queryParams: {
                planid:@ViewBag.planid,
                usernumber: huserid
            },
            nowrap: false,
            emptyMsg: '没有数据',
            singleSelect: true,
            rownumbers: false, //是否加行号
            pagination: false, //是否显式分页
            rowStyler: function (index, row) {
                if (row.status == 0) {
                    return 'color:red;';
                }
            },
            columns: [
                [
                    { field: "deptname", title: "部门", rowspan: 2, align: "center", width: 100 },
                    { field: "inspectionplace", title: "地址", rowspan: 2, align: "center", width: 100 },
                    { field: "insertdate", title: "时间", rowspan: 2, align: "center", width: 100 },
                    { title: "问题", colspan: 2, align: "center", width: 100 },
                    { title: "回复", colspan: 2, align: "center", width: 100 },
                    {
                        field: "status", title: "状态", rowspan: 2, align: "center", width: 100,
                        formatter: function (value, row, index) {
                            if (value == 0) {
                                return '待解决';
                            } else if (value == 1) {
                                return '已解决';
                            }
                        }
                    },
                    { field: "operate", title: "操作", rowspan: 2, width: 100, formatter: operateFormatter},
                ],
                [
                    { field: "question", title: "描述", rowspan: 1, align: "center", width: 100 },
                    { field: "planinspectionquestionimg", title: "图片", rowspan: 1, align: "center", width: 100, formatter: questionImageFormatter},
                    { field: "planinspectionfeedback", title: "描述", rowspan: 1, align: "center", width: 100, formatter: questionImageFormatter},
                    { field: "planinspectionfeedbackimg", title: "图片", rowspan: 1, align: "center", width: 100, formatter: questionImageFormatter},
                ]
            ],
            **onLoadSuccess: function () {
                $('.image-list').on('click', '.cover', function () {
                    var this_ = $(this);
                    var images = this_.parents('.image-list').find('.cover');
                    var imagesArr = new Array();
                    $.each(images, function (i, image) {
                        imagesArr.push($(image).children('img').attr('src'));
                    });
                    $.pictureViewer({
                        images: imagesArr, //需要查看的图片,数据类型为数组
                        initImageIndex: this_.index() + 1, //初始查看第几张图片,默认1
                        scrollSwitch: true //是否使用鼠标滚轮切换图片,默认false
                    });
                });
            }**
        });
  1. 编写datagrid的格式化方法
 function questionImageFormatter(value, row, index) {
        var htmlstr;
        htmlstr = '
'; for (var i = 0; i < row.planinspectionquestionimg.length; i++) { if (i == 0) { htmlstr += "
"; htmlstr += ''; htmlstr += '
'; } else { htmlstr += "
"; htmlstr += ''; htmlstr += '
'; } } htmlstr += '
'; return htmlstr; }
  1. 注意事项
    点击事件的注册一定要在onloadsuccess中注册,否则不起作用
    注意图标的地址
  2. 效果展示
    点击放大图片,滚动鼠标也可以切换自如EasyUI,TopJUI的datagrid显示图片并点击放大浏览_第1张图片
    EasyUI,TopJUI的datagrid显示图片并点击放大浏览_第2张图片

EasyUI,TopJUI的datagrid显示图片并点击放大浏览_第3张图片

  1. js样式下载地址
    https://download.csdn.net/download/silence_dou/12092177

你可能感兴趣的:(项目的技术问题)