How to show Qr Code in Kendo Grid?

a 夏天 提交于 2019-12-06 07:28:13

The template function needs to return a string of the HTML that will be used. I would have the template create an empty DIV in the grid cell with a class="QRME" and a data attribute for the id. Then in the dataBound event of the grid, loop through all the QRME divs, get the id and create the QR codes:

$("#grid").kendoGrid({
  columns: [   {
     field: "Id",
    }, {
    title: "QrCode",
    width: 300,
    template: function(dataItem) {
      return "<div class='QRME' data-id='" + kendo.htmlEncode(dataItem.Id) + "'></div>";
    }
  }],
  dataSource: [ { Id: "1" }, { Id: "2" }, { Id: "3" }  ],
  dataBound: function(e) {
    $("div.QRME").each(function(idx){
         $(this).kendoQRCode({ 
         value: "www.google.com"+ $(this).data("id"),
         errorCorrection: "M",
         size: 120,
         border: {
            color: "#000000",
            width: 5
         }
       });
    });
  }
});

Working DEMO

I can't use dataBound and therefore I was looking for a solution that works with template. First I make a div instance and put the QR code there and return outerHTML.

template: function(dataItem) {
  return jQuery("<div class='qrcode'></div>")
          .kendoQRCode({
          value: kendo.htmlEncode(dataItem["Id"]),
          errorCorrection: "M",
          size: 60,
          border: {
            color: "#000",
            width: 1
          }
        }).html();
}

working DEMO

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!