Server Side rerendering issues resolved :)
I'm submitting a...
hello all, i am writing a complete guide that how can you solve the serverside rerendring issues even having all export buttons and even search which i found angular 7 doc does not have that properly.
[a bug is fixed related to angular ] Bug report
[angular 7 datattable ] Feature request
[ ] Documentation issue or request
[this is tested with latest angular 7 datatable for any serverside rerendering issue you can solve it here. ] Question
Current behavior
Expected behavior
Minimal reproduction of the problem with instructions
Environment
- node version:
- angular version:
- angular-cli version:
- jquery version:
- datatables version:
- angular-datatables version:
Your html should have code like this here you will find #dataTable which is basically working as id like jquery datatable but with the angular base
@ViewChild(DataTableDirective) dtElement: DataTableDirective; dtOptions: DataTables.Settings = {};
// before constructor ends
now this will be your ngOnInit
ngOnInit(): void {
const header = new HttpHeaders().set('Authorization', 'Bearer ' + this.auth.getToken());
const that = this;
this.dtOptions = {
dom: 'lBfrtip',
pagingType: 'full_numbers',
pageLength: 10,
processing: true,
serverSide: true,
ajax: (dataTablesParameters: any, callback) => {
that.api_check ? that.api_check.unsubscribe() : that.api_check = null;
that.api_check = that.http
.post
// custom column of row click event start
// Unbind first in order to avoid any duplicate handler
// (see https://github.com/l-lin/angular-datatables/issues/87)
// $('td:last-child', row).unbind('click');
// $('td:last-child', row).bind('click', () => {
// self.nextButtonClickEvent(data);
// });
// $('td:first-child', row).unbind('click');
// $('td:first-child', row).bind('click', () => {
// self.nextButtonClickEvent(data);
// });
// custom column of row click event ends
// below code will give you row click event data
$('tr', row).unbind('click');
$('td', row).bind('click', () => {
console.log(data);
});
return row;
},
columns: [
{
title: 'Member#',
data: 'member_id',
defaultContent: '',
orderable: true,
searchable: true
},
{
title: 'Name',
data: 'first_name',
render: function (data, type, row) {
return row.first_name + ' ' + row.last_name; },
//data: 'first_name',
defaultContent: '',
orderable: true,
searchable: true
},
{
title: 'Contact#',
data: 'contact_no',
defaultContent: '',
orderable: true,
searchable: true
},
{
title: 'Birth Date',
data: 'date_of_birth',
defaultContent: '',
orderable: true,
searchable: true
},
{
title: 'Age',
data: 'age',
defaultContent: '',
orderable: true,
searchable: false
},
],
language: {
'processing':
' <divclass="my-preloader preloader my-modal"><svg class="circular" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /></svg></div>',
}
};
// this is the main part that will help you in rerendering :)
that.dataTable = $(that.table.nativeElement);
that.dataTable.DataTable(that.dtOptions);
}
thats it enjoy the coding! one note rest datatable integration is like @l-lin documentation this will help you solve serverside rerendering