在数据表中显示图像codeigniter

时间:2017-05-28 06:39:39

标签: codeigniter web datatable

抱歉我的英语不好, 我想使用数据表在我的表中显示图像。

 var t = $("#mytable").dataTable({
                initComplete: function() {
                    var api = this.api();
                    $('#mytable_filter input')
                    .off('.DT')
                    .on('keyup.DT', function(e) {
                        if (e.keyCode == 13) {
                            api.search(this.value).draw();
                        }
                    });
                },
                oLanguage: {
                    sProcessing: "loading..."
                },
                processing: true,
                serverSide: true,
                ajax: {"url": "wisataadmincontroller/json", "type": "POST"},
                columns: [
                {
                    "data": "id_wisata",
                    "orderable": false
                },{"data": "nama_wisata"},{"data": "alamat_wisata"},{"data": "no_telp"},{"data": "kategori"},{"data": "longitude"},{"data": "latitude"},{"data": "gambar","render": function(data, type, row) {
                    return '<img src="'+data+'"style="height:100px;width:100px;" />';
                }},{"data": "like"},
                {
                    "data" : "action",
                    "orderable": false,
                    "className" : "text-center"
                }
                ],
                order: [[0, 'desc']],
                rowCallback: function(row, data, iDisplayIndex) {
                    var info = this.fnPagingInfo();
                    var page = info.iPage;
                    var length = info.iLength;
                    var index = page * length + (iDisplayIndex + 1);
                    $('td:eq(0)', row).html(index);
                }
            });
        });

结果:the images are empty

图像为空,因为图像源仅包含图像文件名, 那么如何在数据表中使用baseurl?

1 个答案:

答案 0 :(得分:1)

只需将其插入?

<img src="<?php echo base_url(); ?>'+data+'"style="height:100px;width:100px;" />