eu tenho o seguinte script abaixo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A Pen by Jason</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/css/patternfly.min.css'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/css/patternfly-additions.min.css'>
</head>
<body>
<!-- Table HTML -->
<table class="table table-striped table-bordered table-hover" id="table1">
<thead>
<tr>
<th>
<label class="sr-only" for="selectAll">Select all rows</label>
<input type="checkbox" id="selectAll" name="selectAll">
</th>
<th>Rendering Engine</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Engine Version</th>
<th>CSS Grade</th>
<th colspan="2">Actions</th>
</tr>
</thead>
</table>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js'></script>
<script src='https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/js/patternfly.dataTables.pfFilter.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/js/patternfly.dataTables.pfPagination.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/js/patternfly.dataTables.pfResize.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/patternfly/3.40.0/js/patternfly.min.js'></script>
<script>
// Initialize Datatables
$(document).ready(function() {
$(".datatable").dataTable();
});
$(document).ready(function() {
// JSON data for Table View
var dataSet = [{
engine: "Trident",
browser: "Internet Explorer 4.0",
platforms: "Win 95+",
version: "4",
grade: "X"
}, {
engine: "Trident",
browser: "Internet Explorer 5.0",
platforms: "Win 95+",
version: "5",
grade: "C"
}];
// DataTable Config
$("#table1").DataTable({
columns: [{
data: null,
className: "table-view-pf-select",
render: function(data, type, full, meta) {
// Select row checkbox renderer
var id = "select" + meta.row;
return (
'<label class="sr-only" for="' +
id +
'">Select row ' +
meta.row +
'</label><input type="checkbox" id="' +
id +
'" name="' +
id +
'">'
);
},
sortable: false
}, {
data: "engine"
}, {
data: "browser"
}, {
data: "platforms"
}, {
data: "version"
}, {
data: "grade"
}, {
data: null,
className: "table-view-pf-actions",
render: function(data, type, full, meta) {
// Inline action button renderer
return '<div class="table-view-pf-btn"><button class="btn btn-default" type="button">Actions</button></div>';
}
}, {
data: null,
className: "table-view-pf-actions",
render: function(data, type, full, meta) {
// Inline action kebab renderer
return (
'<div class="dropdown dropdown-kebab-pf">' +
'<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">' +
'<span class="fa fa-ellipsis-v"></span></button>' +
'<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight">' +
'<li class ="send-delete" id="send-delete"><a href="#">Delete Row</a></li>' +
'<li role="separator" class="divider"></li>' +
'<li><a href="#">Update Row</a></li></ul></div>'
);
}
}],
data: dataSet,
dom: "t",
language: {
zeroRecords: "No records found"
},
order: [
[1, "asc"]
]
});
});
// #################################### deleta linha
$(function(){
$(".send-delete").click(function(event){
event.preventDefault();
var idrow = meta.row
});
});
</script>
</body>
</html>
Eu preciso que quando o usuário clicar no botão delete row, minha função:
$(function(){
$(".send-delete").click(function(event){
event.preventDefault();
var idrow = meta.row;
});
});
Que está ligada ao evento do botão em HTML:
<li class ="send-delete" id="send-delete"><a href="#">Delete Row</a></li>
Receba o valor meta.row que está dentro do meu data table:
$("#table1").DataTable({
columns: [{
data: null,
className: "table-view-pf-select",
render: function(data, type, full, meta) {
// Select row checkbox renderer
var id = "select" + meta.row;
return (
'<label class="sr-only" for="' +
id +
'">Select row ' +
meta.row +
'</label><input type="checkbox" id="' +
id +
'" name="' +
id +
'">'
);
},
Porém sempre que tento retornar este valor ele dá erro, qual melhor forma de acessar esse valor com minha function?