如何在handsontable 的单元格内添加自定义按钮?

问题描述 投票:0回答:4

我试图在handsontable 的每一行末尾添加一个自定义保存按钮。 我在 Laravel 4 中使用 Handsontable 包。

按钮显示如下:

enter image description here

<button>Save</button>
button handsontable
4个回答
9
投票

尝试使用

htmlRenderer

演示:http://docs.handsontable.com/0.19.0/demo-custom-renderers.html

var actionRenderer = function (instance, td, row, col, prop, value, cellProperties) {
  var $button = $('<button>');
  $button.html(value)
  $(td).empty().append($button); //empty is needed because you are rendering to an existing cell
};

var $container = $("#example1");
$container.handsontable({
  /*....*/
  columns: [
    /*....*/
    {data: "action", renderer: actionRenderer}
  ]
});

为了获得更好的性能,渲染器可以用纯 JavaScript 编写


4
投票

我找到了我自己问题的答案.. 我在handsontable中使用“渲染器”将单元格渲染为HTML

columns: [
                    {data: "unique_no"},
                    {data: "title"},
                    {data: "subject"},
                    {data: "year"},
                    {data: "duration"},
                    {data: "color"},
                    {data: "language"},
                    {data: "synopsis"},
                    {data: "director"},
                    {data: "basic_format"},
                    {data: "created_at"},
                    {data: "updated_at"},
                    {data: "action", renderer: "html",readOnly: true}

                  ],

这是我找到它的地方http://handsontable.com/demo/renderers_html.html#dropdown


2
投票

您可以简单地执行此自定义渲染器。

columns: [
    { data: 'basicFormat', renderer: 'text'},
    { data: 'createdAt', renderer: 'text'},
    { data: 'updatedAt', renderer: 'text'},
    { data: 'action', renderer: 'html'},    
]

0
投票
document.addEventListener("DOMContentLoaded", function() {

  var
    data = [{}, {},
      {
        title: createNew()
      }
    ],
    container1,
    hot1;
  
  container1 = document.getElementById('example1');
  hot1 = new Handsontable(container1, {
    data: data,
    colWidths: 220,
    colHeaders: true,
    columns: [
      {data: "title", renderer: "html"}
    ]
  });

  
 function createNew(){
    return "<div class='new'>button</div>"
 };

var button = document.querySelector('.new');
button.addEventListener('click', function(){
    alert('button')
})

});
© www.soinside.com 2019 - 2024. All rights reserved.