Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a custom Button inside a cell in handsontable?

I am trying to add a custom save button at the end of each row in handsontable. I am using handsontable package in laravel 4.

The button shows up like this:

enter image description here

<button>Save</button>
like image 596
aps5842 Avatar asked Jul 16 '14 07:07

aps5842


Video Answer


3 Answers

Try using htmlRenderer

Demo: 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}
  ]
});

For better performance, the renderer could be written in pure JavaScript

like image 67
warpech Avatar answered Oct 20 '22 02:10

warpech


I found an answer to my own question.. I used "renderer" in handsontable to render the cell into 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}

                  ],

This is where I found it http://handsontable.com/demo/renderers_html.html#dropdown

like image 36
aps5842 Avatar answered Oct 20 '22 02:10

aps5842


you can simply do this custom renderer.

columns: [
    { data: 'basicFormat', renderer: 'text'},
    { data: 'createdAt', renderer: 'text'},
    { data: 'updatedAt', renderer: 'text'},
    { data: 'action', renderer: 'html'},    
]
like image 2
Sagar Avatar answered Oct 20 '22 00:10

Sagar