I'm trying to use Angular DataTables with the server side processing option, but when I try to enable it in their "Angular way example", only the first request gets rendered, the subsequent requests (paging, ordering, searching) are sent but they never update the table.
相关问题
- Angular RxJS mergeMap types
- Carriage Return (ASCII chr 13) is missing from tex
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Using :remote => true with hover event
- Is there a way to play audio on a mobile browser w
After a little digging, I found an unrelated user contributed note that suggests that you override the
ajax
option with your own function to handle the server side call.The trick here is to return an empty array to the DataTables callback, so it won't use its renderer to render the table. That will be done by Angular. It's also a good idea to specify the columns names to the server.
Since DataTables will think there are no rows to display, it will show the "No data available" message. The simplest way to handle it is to hide it with CSS. You can add it to your global styles.css:
then show it yourself in the template:
So here's the complete code. Tested with Angular 5.0.0, datatables.net 1.10.16 and angular-datatables 5.0.0:
angular-way-server-side.component.ts
angular-way-server-side.component.html
angular-way-server-side.component.css
person.ts
datatables-response.ts
src/styles.css
The server side is implemented pretty much the same way as if you were using DataTables with JavaScript/jQuery. You can see a very simple sample implementation in PHP.