Skip to content

Commit

Permalink
Merge pull request #1760 from l-lin/no-server-ajax-callback
Browse files Browse the repository at this point in the history
chore(demo): show static text on preview for ajax callback
  • Loading branch information
l-lin authored Nov 13, 2023
2 parents 0a66237 + bd57553 commit aef340e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-datatables-demo",
"version": "16.0.0",
"version": "17.0.1",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<ng-template #preview>
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table>
<blockquote>
<p>No preview as we do not have a server that can serve the queries.</p>
</blockquote>
</ng-template>
<app-base-demo [pageTitle]="pageTitle" [mdIntro]="mdIntro" [mdHTML]="mdHTML" [mdTS]="mdTS" [template]="preview">
</app-base-demo>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClientModule } from '@angular/common/http';
import { SecurityContext, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableDirective, DataTablesModule } from 'angular-datatables';
import { AppRoutingModule } from 'app/app.routing';
Expand Down Expand Up @@ -50,15 +49,4 @@ describe('WithAjaxCallbackComponent', () => {
expect(app.pageTitle).toBe('AJAX with callback');
}));

it('should have table populated via AJAX', async () => {
const app = fixture.debugElement.componentInstance as WithAjaxCallbackComponent;
await fixture.whenStable();
expect(app.dtOptions.columns).toBeDefined();
const query = fixture.debugElement.query(By.directive(DataTableDirective));
const dir = query.injector.get(DataTableDirective);
expect(dir).toBeTruthy();
const instance = await dir.dtInstance;
fixture.detectChanges();
expect(instance.rows().length).toBeGreaterThan(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { DataTablesResponse } from 'app/datatables-response.model';

@Component({
selector: 'app-with-ajax-callback',
Expand All @@ -22,19 +21,6 @@ export class WithAjaxCallbackComponent implements OnInit {
ngOnInit(): void {
const that = this;
this.dtOptions = {
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'https://xtlncifojk.eu07.qoddiapp.com/',
dataTablesParameters, {}
).subscribe(resp => {
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: resp.data
});
});
},
columns: [{
title: 'ID',
data: 'id'
Expand Down

0 comments on commit aef340e

Please sign in to comment.