How to display thumbnail, by fetching url from sql database

How to display thumbnail, by fetching url from sql database

chetankchandakchetankchandak Posts: 8Questions: 2Answers: 0

My server side script containd following code

Editor::inst( $this->editorDb, 'tbl_order_details', 'details_id' )
     ->field(
    Field::inst( 'tbl_order_details.order_id' ),
    Field::inst( '**tbl_order_details.fabric1**' )  )

tbl_order_details.fabric1 fetches me url from sql database, where the url path is stored.

Below is my javascript:

columns: [
        {
            data: null,
            defaultContent: '',
            className: 'select-checkbox',
            orderable: false,
            searchable: false
        },
        { data: "tbl_products.name", editField: "tbl_order_details.items_id" },
        { data: "tbl_order_details.order_id" },
        { data: "tbl_order_details.fabric1" }, ],

The final result shows me only the url, (i.e. uploads/order_details/2/202213318.jpg), but i want the thumbnail of the image in the table.
Where and how should i enter the html <img src="tbl_order_details.order_id""> to display the thumbnail in the cell.

Answers

  • LukasLLukasL Posts: 26Questions: 10Answers: 0
    edited October 2020

    You may want to check out the columns.render option.

    Here's an example with an anchor tag using data from the first column: http://live.datatables.net/wegowafu/177/edit

    You would just do the same by targeting your tbl_order_details.fabric1 column and returning an image tag.

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • chetankchandakchetankchandak Posts: 8Questions: 2Answers: 0

    well I got it.
    Solution-

    columns: [
    {
    data: null,
    defaultContent: '',
    className: 'select-checkbox',
    orderable: false,
    searchable: false
    },
    { data: "tbl_products.name", editField: "tbl_order_details.items_id" },
    { data: "tbl_order_details.order_id" },
    {{ "data": "tbl_order_details.fabric1",
    "render": function(data, type, row)
    {return '<img src="'+data+'" width="50px" />';}
    }
    ],

This discussion has been closed.