green user green user - 1 month ago 7
HTML Question

lfetch data from table to text box

I am creating a table through jQuery and in this table I concatenate 3 columns in 1 column:

so how i concatenate multiple columns in 1 column
Before concatenate:

if (re.length > 0) {
$("#services_schdulue").append
$('#services_schdulue thead').append("<tr><th>Service ID</th><th>Service Type</th><th>frequency</th><th>Freq_Duration</th><th>Freq_Mileage</th></tr>");

for (var i = 0; i < re.length; i++) {
if (re[i] !== null) {
$('#services_schdulue tbody').append('<tr><td>' + re[i][0] +
'</td><td>' + re[i][1] +
'</td><td>' + re[i][2] +
'</td><td>' + re[i][3]
'</td><td>' + re[i][4] +
'</td></tr>');
}
}
}


After concatenate:

if (re.length > 0) {
$("#services_schdulue").append
$('#services_schdulue thead').append("<tr><th>Service ID</th><th>Service Type</th><th>S freq</th></tr>");

for (var i = 0; i < re.length; i++) {
if (re[i] !== null) {
$('#services_schdulue tbody').append('<tr><td>' + re[i][0] +
'</td><td>' + re[i][1] +
'</td><td>' + re[i][2] + '' + re[i][3] + '' + re[i][4] +
'</td></tr>');
}
}
}

var myTable = $('#services_schdulue').DataTable({
"columnDefs": [{
"visible": false,
"targets": [3,4,5]
}]
});

Answer

Try below solution , i think this will help you.

$('#services_schdulue').on('click', 'tr', function () {
        var row = $(this)[0];
        console.log(re[row._DT_RowIndex]);
});

In console you find the entire data of the row , which row you click.

As per your jsfiddle, below solution is help to you. Don't fogot to declare variable re outside of the document.ready

    $('#tabledata').on('click', 'tr', function () {

        $("#myModal").modal("show");
            var row = $(this);
            var row_index = row[0]._DT_RowIndex;
            var data = re[row_index];

            $("#txt_status").val(data.Status);
            debugger;
            //var repeat = myTable.row.find('td')[2].firstChild.data;
            $("#txt_speed").val(data.Speed);
        });
Comments