I am trying to use remove row context menu to delete the row from the MySQL table also. I am just follow the PHP demo with very small alteration.
How can I do that ?
I am trying to use remove row context menu to delete the row from the MySQL table also. I am just follow the PHP demo with very small alteration.
How can I do that ?
Hi @dassoubarna
Unfortunately we do not have a similar demo. Did you tried to check at Stackoverflow? Guys there share great examples how to connect your instance with backend.
I try something like this:
Handsontable.hooks.add('afterRemoveRow', function(index, amount) {
console.log(index);
console.log(amount);
$.ajax({
url: "php/delete.php",
data: index
});
});
And in delete.php
require_once('functions.php');
try {
$db = getConnection();
$ID = $_POST['index'];
$query = $db->prepare('DELETE FROM cars WHERE id = $ID');
$query->execute();
closeConnection($db);
}
catch (PDOException $e) {
print 'Exception : ' . $e->getMessage();
}
But unfortunately it’s not working.
Resolved… Final codes are
Handsontable.hooks.add('afterRemoveRow', function(index, amount) {
var data = index + 1;
$.ajax({
url: "php/delete.php",
data: {ID: data},
dataType: 'json',
type: 'POST',
success: function (res) {
if (res.result === 'ok') {
$console.text('Row Deleted');
}
else {
$console.text('Delete error');
}
},
error: function () {
$console.text('Delete error');
}
});
});
And delete.php
require_once('functions.php');
try {
//open the database
$db = getConnection();
$ID = $_POST['ID'];
$select = $db->prepare('DELETE FROM cars WHERE id="'.$ID.'"');
$select->execute();
$out = array(
'result' => 'ok'
);
echo json_encode($out);
closeConnection($db);
}
catch (PDOException $e) {
print 'Exception : ' . $e->getMessage();
}
But unfortunately another problem arises. Handsontable shows a blank row for the missing(deleted) id from the database. Is there a way to hide blank rows in Handsontable except the last one (minSpareRows: 1)?
Hi @dassoubarna
you can use isEmptyRow
to check if the row with given index is empty and if it is pass it to an array for hidden rows. Of course you can exclude the last row
Is there any example available for isEmptyRow
?
I’ve missed your last question. Sorry for that.
Have you already made the part of code that needed that method?
No. But I try to solve it another way.
OK. So I will close this issue.
If you would have any other questions please create a new one.