Save Button in a row

1,030 views
Skip to first unread message

pete.s...@googlemail.com

unread,
Aug 18, 2014, 4:12:42 AM8/18/14
to handso...@googlegroups.com
At the moment I'm using auto save but I would rather have a button in a column to save a row when the user has finished entering.

I've tried adding custom html to have a button in a column but handsontable captures all the events.

Is there a way to have a save button in a column?

Matt Vagnoni

unread,
Aug 18, 2014, 5:10:44 PM8/18/14
to handso...@googlegroups.com, pete.s...@googlemail.com
I don't think so.  I think the best you could do is place a button centered over a column.  There's a few events (e.g. afterColumnResize) that'd probably help with handling all that jaz.  I admit, its something I've been looking into myself for other reasons.  

trebuchetty

unread,
Aug 18, 2014, 6:10:06 PM8/18/14
to handso...@googlegroups.com, pete.s...@googlemail.com
I have a button renderer for this:

var buttonRenderer = function (instance, td, row, col, prop, value, cellProperties) {
                Handsontable.renderers.TextRenderer.apply(this, arguments);
                var $td = $(td);
                ...
                var rowData = instance.getDataAtRow(row);
                $td.html('<button class="btn btn-default btn-xs saveBtn" data-rowIndex="' + row + '" >Save</button>');
            }

then an onClick event handler for the "saveBtn" class.

trebuchetty

unread,
Aug 18, 2014, 6:12:29 PM8/18/14
to handso...@googlegroups.com, pete.s...@googlemail.com
Mine's actually a bit more complicated than that, as I check to see if the item has already been saved and adjust the button accordingly, but that should give you the general idea.

pete.s...@googlemail.com

unread,
Aug 19, 2014, 5:16:21 AM8/19/14
to handso...@googlegroups.com, pete.s...@googlemail.com

Thank you everyone for pointing me in the right direction.

I've added a column to the end of my handsontable:

{ data: "button", renderer: "html", readOnly: true }

In the "afterChange: function (change, source)"

I added:

row = change[0];
thisrow = row[0];
if (row[1] == "button") return
obj = data[thisrow];
var btn = '<input type="button" class="btn btn-primary btn-sm" value="save">'
$('#example1').handsontable("setDataAtCell", thisrow, 3, btn);

This adds a button to the last column when a cell is edited. I haven't bothered to check if the button is already there.

Finally, I capture the selection of the button cell:

Handsontable.PluginHooks.add('afterSelection', function (row, column) {
var current_td = this.getCell(row, column);
if (column != 3) return;
$('#example1').handsontable("setDataAtCell", row, 3, "");
// save a row here
});

You'll need to add the code to save the row.

dmvi...@gmail.com

unread,
Feb 16, 2018, 7:17:51 PM2/16/18
to Handsontable
do you happen to have a demo of this? JsFiddle or something?

Pete Suffolk

unread,
Feb 19, 2018, 4:37:31 AM2/19/18
to handso...@googlegroups.com
Hi

I don't have an example as I switched to using bootgrid and modal popups for the edits.

Regards

Pete


--
You received this message because you are subscribed to a topic in the Google Groups "Handsontable" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/handsontable/pEkDpJA3M3k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to handsontable+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages