How to select row in datatable that is populated after button click
How to select row in datatable that is populated after button click
maj
Posts: 1Questions: 1Answers: 0
I'm using below code 1 to populate my datatable. However, when I tried to access my datatable using code 2, I dont get this response: alert( customerTable.row( this ).data() );
What am I doing wrong here?
Code 1
$(searchClientBtn).on("click", function () {
var clientLastName = $(clientLastNameTxt).val();
var clientFirstName = $(clientFirstNameTxt).val();
var clientMiddleName = $(clientMiddleNameTxt).val();
var clientDateOfBirth = $(clientDateOfBirthTxt).val();
if ( clientLastName.length == 0 && clientFirstName.length == 0 && clientMiddleName.length == 0 ) {
alert("Please enter search parameter/s to proceed.");
}
else {
var formData = new FormData();
formData.append("firstName", $("#clientFirstNameTxt").val());
formData.append("middleName", $("#clientMiddleNameTxt").val());
formData.append("lastName", $("#clientLastNameTxt").val());
formData.append("dateOfBirth", $("#clientDateOfBirthTxt").val());
//console.log(formData);
var booking = new booking();
booking.getListCustomer(formData, {
onSuccess: function (xdata) {
var customerTable = $("#customerTable").DataTable({
data: xdata.result,
processing: true,
columns: [
{ 'data': 'FirstName' },
{ 'data': 'MiddleName' },
{ 'data': 'LastName' },
{ 'data': 'Birthdate' }
]
});
},
onError: function (xdata) {
alert("An error occured");
}
});
$(clientSearchModal).modal("show");
}
});
Code 2
$("#customerTable").on("click", "tbody tr", function () {
alert("imclicked");
alert( customerTable.row( this ).data() );
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin