简体   繁体   中英

How to show default image if image field is null in kendo grid ?

i want to show default image if image field is null.This is my image field code.

{ field: "Photo",
title: "Photo",
template: '<img src="#= Photo #" alt="image" width="80px" height="80px" />',
width: 100
}

Try this

{
    field: "Photo",
    title: "Photo",
    template: function(dataItem) {
        return kendo.template(
           '<img src="#= Photo #" alt="image" width="80px" height="80px" />'
        )({Photo: dataItem.Photo || 'http://path-to-image'});
    }
    width: 100
}

This dataItem.Proto || 'http://path-to-image' dataItem.Proto || 'http://path-to-image' means if Photo is falsy ( null , false , 0 , '' , undefined ) then use default path

Example

Simple!

{
    field: "Photo",
    title: "Photo",
    template: '<img src="#= Photo == null ? "http://exemple.com/pic.jpg" : Photo #" alt="image" width="80px" height="80px" />',
    width: 100
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM