【问题标题】:How do I create two images in same column within a slickgrid?如何在 slickgrid 的同一列中创建两个图像?
【发布时间】:2013-04-24 11:05:12
【问题描述】:

我试图在我的 slickgrid 的一列中选择并删除图像,但我无法这样做。我了解如何像这样执行单个图像按钮。 :

var column = {id:delCol, field:'del', name:'Delete', width:250, formatter:buttonFormatter}

//Now define your buttonFormatter function
function buttonFormatter(row,cell,value,columnDef,dataContext){  
    var button = "<input class='del' type='button' id='"+ dataContext.id +"' />";
    //the id is so that you can identify the row when the particular button is clicked
    return button;
    //Now the row will display your button
}

关于如何做到这一点的任何想法?

【问题讨论】:

    标签: c# asp.net-mvc-4 slickgrid


    【解决方案1】:

    该单元格的数据应包含图像/按钮所需的任何内容,可以是数组或 {}(对象)。

    然后创建一个格式化程序,以便在单元格中同时使用两者:

    // if value is [dataContext.delete.id, dataContext.add.id] for example
    function twoButtonFormatter(row, cell, value, columnDef, dataContext) {
      var str = ''; // initialize a string
    
      // First button
      str += "<input class='del' type='button' id='"+ value[0] +"' /> ";
    
      // second button
      str += "<button data-id='"+value[1]+"' class='add'>Add</button>";
    
      // return the html string of both buttons
      return str;
    }
    

    【讨论】:

    • 效果很好,奇怪的是我之前尝试过这样的事情并且遇到了错误。一定是设置不正确。感谢代码 sn-p。
    猜你喜欢
    • 2013-09-23
    • 2020-03-24
    • 1970-01-01
    • 2011-12-21
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多