Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 4e03350

Browse files
committed
Add AJAX callback and new server side examples
1 parent f8dde0f commit 4e03350

16 files changed

+267
-1
lines changed

demo/src/app/app.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ <h3>
4141
<li>
4242
<a class="waves-effect waves-blue" routerLink="/basic/with-options">With options</a>
4343
</li>
44+
<li>
45+
<a class="waves-effect waves-blue" routerLink="/basic/with-ajax-callback">AJAX using DT callback</a>
46+
</li>
47+
<li>
48+
<a class="waves-effect waves-blue" routerLink="/basic/new-server-side">Server side</a>
49+
</li>
4450
<li>
4551
<a class="waves-effect waves-blue" routerLink="/advanced/row-click-event">Row click event</a>
4652
</li>

demo/src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { FAQComponent } from './f-a-q/f-a-q.component';
4646
import { UsingNgTemplateRefComponent } from './advanced/using-ng-template-ref.component';
4747
import { DemoNgComponent } from './advanced/demo-ng-template-ref.component';
4848
import { MoreHelpComponent } from './more-help/more-help.component';
49+
import { WithAjaxCallbackComponent } from './basic/with-ajax-callback/with-ajax-callback.component';
50+
import { NewServerSideComponent } from './basic/new-server-side/new-server-side.component';
4951

5052
@NgModule({
5153
declarations: [
@@ -78,7 +80,9 @@ import { MoreHelpComponent } from './more-help/more-help.component';
7880
FAQComponent,
7981
UsingNgTemplateRefComponent,
8082
DemoNgComponent,
81-
MoreHelpComponent
83+
MoreHelpComponent,
84+
WithAjaxCallbackComponent,
85+
NewServerSideComponent
8286
],
8387
imports: [
8488
BrowserModule,

demo/src/app/app.routing.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { UsingNgPipeComponent } from './advanced/using-ng-pipe.component';
2828
import { FAQComponent } from './f-a-q/f-a-q.component';
2929
import { UsingNgTemplateRefComponent } from './advanced/using-ng-template-ref.component';
3030
import { MoreHelpComponent } from './more-help/more-help.component';
31+
import { WithAjaxCallbackComponent } from './basic/with-ajax-callback/with-ajax-callback.component';
32+
import { NewServerSideComponent } from './basic/new-server-side/new-server-side.component';
3133

3234
const routes: Routes = [
3335
{
@@ -63,6 +65,14 @@ const routes: Routes = [
6365
path: 'basic/with-ajax',
6466
component: WithAjaxComponent
6567
},
68+
{
69+
path: 'basic/with-ajax-callback',
70+
component: WithAjaxCallbackComponent
71+
},
72+
{
73+
path: 'basic/new-server-side',
74+
component: NewServerSideComponent
75+
},
6676
{
6777
path: 'basic/angular-way',
6878
component: AngularWayComponent

demo/src/app/basic/new-server-side/new-server-side.component.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ng-template #preview>
2+
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table>
3+
</ng-template>
4+
<app-base-demo [pageTitle]="pageTitle" [mdIntro]="mdIntro" [mdHTML]="mdHTML" [mdTS]="mdTS" [template]="preview">
5+
</app-base-demo>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { NewServerSideComponent } from './new-server-side.component';
4+
5+
describe('NewServerSideComponent', () => {
6+
let component: NewServerSideComponent;
7+
let fixture: ComponentFixture<NewServerSideComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ NewServerSideComponent ]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(NewServerSideComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { Component, OnInit } from '@angular/core';
3+
import { DataTablesResponse } from 'app/datatables-response.model';
4+
5+
@Component({
6+
selector: 'app-new-server-side',
7+
templateUrl: './new-server-side.component.html',
8+
styleUrls: ['./new-server-side.component.css']
9+
})
10+
export class NewServerSideComponent implements OnInit {
11+
12+
constructor(
13+
private http: HttpClient
14+
) { }
15+
16+
pageTitle = 'Server-side processing';
17+
mdIntro = 'assets/docs/basic/new-server-side/intro.md';
18+
mdHTML = 'assets/docs/basic/new-server-side/source-html.md';
19+
mdTS = 'assets/docs/basic/new-server-side/source-ts.md';
20+
21+
dtOptions: DataTables.Settings = {};
22+
23+
ngOnInit(): void {
24+
const that = this;
25+
this.dtOptions = {
26+
serverSide: true,
27+
ajax: (dataTablesParameters: any, callback) => {
28+
that.http
29+
.post<DataTablesResponse>(
30+
'https://xtlncifojk.eu07.qoddiapp.com/',
31+
dataTablesParameters, {}
32+
).subscribe(resp => {
33+
callback({
34+
recordsTotal: resp.recordsTotal,
35+
recordsFiltered: resp.recordsFiltered,
36+
data: resp.data
37+
});
38+
});
39+
},
40+
columns: [{
41+
title: 'ID',
42+
data: 'id'
43+
}, {
44+
title: 'First name',
45+
data: 'firstName'
46+
}, {
47+
title: 'Last name',
48+
data: 'lastName'
49+
}]
50+
};
51+
}
52+
}
53+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ng-template #preview>
2+
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table>
3+
</ng-template>
4+
<app-base-demo [pageTitle]="pageTitle" [mdIntro]="mdIntro" [mdHTML]="mdHTML" [mdTS]="mdTS" [template]="preview">
5+
</app-base-demo>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { WithAjaxCallbackComponent } from './with-ajax-callback.component';
4+
5+
describe('WithAjaxCallbackComponent', () => {
6+
let component: WithAjaxCallbackComponent;
7+
let fixture: ComponentFixture<WithAjaxCallbackComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ WithAjaxCallbackComponent ]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(WithAjaxCallbackComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { Component, OnInit } from '@angular/core';
3+
import { DataTablesResponse } from 'app/datatables-response.model';
4+
5+
@Component({
6+
selector: 'app-with-ajax-callback',
7+
templateUrl: './with-ajax-callback.component.html'
8+
})
9+
export class WithAjaxCallbackComponent implements OnInit {
10+
11+
constructor(
12+
private http: HttpClient
13+
) { }
14+
15+
pageTitle = 'AJAX with callback';
16+
mdIntro = 'assets/docs/basic/with-ajax-callback/intro.md';
17+
mdHTML = 'assets/docs/basic/with-ajax-callback/source-html.md';
18+
mdTS = 'assets/docs/basic/with-ajax-callback/source-ts.md';
19+
20+
dtOptions: DataTables.Settings = {};
21+
22+
ngOnInit(): void {
23+
const that = this;
24+
this.dtOptions = {
25+
ajax: (dataTablesParameters: any, callback) => {
26+
that.http
27+
.post<DataTablesResponse>(
28+
'https://xtlncifojk.eu07.qoddiapp.com/',
29+
dataTablesParameters, {}
30+
).subscribe(resp => {
31+
callback({
32+
recordsTotal: resp.recordsTotal,
33+
recordsFiltered: resp.recordsFiltered,
34+
data: resp.data
35+
});
36+
});
37+
},
38+
columns: [{
39+
title: 'ID',
40+
data: 'id'
41+
}, {
42+
title: 'First name',
43+
data: 'firstName'
44+
}, {
45+
title: 'Last name',
46+
data: 'lastName'
47+
}]
48+
};
49+
}
50+
}

0 commit comments

Comments
 (0)