I use DataTables on Angular7. I have js function on .ts file. And I get 'this.title is not a function' error.
code in my view file is as follow:
$(document).ready(function () {
$('#example').DataTable({
...
initComplete: function () {
const that = this;
that.api().columns().every(function (index) {
var e;
switch (this.title()) {
case "Description":
e = $('<input type="text" class="form-control form-control-sm form-filter m-input" data-col-index="'
+ this.index() + '"/>');
break;
}
});
}
});
});
If you're trying to modify DOM element that corresponds to column header, you may need to employ column().header() method. So your this.title()
should be this.header().textContent
.
You can used this to get column name and it works for me.
var table = $("#extable").DataTable();
var column_name= table.column(0).header().innerText;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.