I have to convert this rows to array per column in selected rows, i used C# MVC.
This is the view before and after click :
Selecting rows after click the button
here's the code :
@if (Model != null)
{
<table id="tablePenerima" class="table table-striped table-bordered animate__animated animate__fadeInRight" cellpadding="0" cellspacing="0">
<thead>
<tr>
@foreach (DataColumn col in Model.Tables[0].Columns)
{
<th align="center">@col.ColumnName</th>
}
</tr>
</thead>
<tbody>
@foreach (DataRow row in Model.Tables[0].Rows)
{
<tr>
@foreach (DataColumn col in Model.Tables[0].Columns)
{
<td align="center">@row[col.ColumnName]</td>
}
</tr>
}
</tbody>
</table>
}
else
{
<p style="color:red;"> Mohon upload file dahulu </p>
}
<div class="form-group">
<button type="button" name="Blast" id="btnBlast" class="btn btn-lg btn-success"><span><i class="fas fa-bolt"> </i></span>BLAST</button>
</div>
and the JS :
$(document).ready(function () {
var table = $('#tablePenerima').DataTable({
dom: 'Bfrtip',
buttons: [
'selectAll',
'selectNone',
],
select: true
});
$('#tablePenerima tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
});
$('#btnBlast').click(function () {
var rowdata = table.rows('.selected').data().toArray();
var msg = '';
for (var i = 0; i < rowdata.length; i++) {
msg += rowdata[i]+ '\n'
}
alert(msg);
})
});
That's all. I want to change the output to be [array0] [array1] [array2] [array4] by per column because i want to use them in futher validation and method inside FOR condition in JS. Thank you :)