0

I have a small web-app that accepts input from a human to create search params. I'm using ng-model-options to debounce the ng-change function to execute the search.

I have small arrows next to the column names on the table that lets users sort (there are three icons - up-down, up, and down for the sort_field and sort_order displayed using ng-class) ; I would like to register a change on those and execute a search after a small delay using debounce. The problem is I'm not sure how use ng-model to bind the particular param to those icons. I don't want someone hammering on the sort icons and crashing the server or their browser.

What I would rather do is have one place on the page that says to watch the search_param object and fire a search 500 milliseconds after whenever it has changed. This way any of the input fields or sort selections would be called when a user is done editing them which triggers a function to send those params to the endpoint.

What is the strategy in AngularJS to do this? Right now all input fields bind a field in the search_param object and have ng-model-options to debounce on change. This is a lot of repeated code.

user3186332
  • 345
  • 3
  • 13
  • Do you use the same function for `ng-change` everywhere? In that case you could use `$timeout`, and if there isn't any search in queue, you could start one with `$timeout`. If there is, just cancel the `$timeout` and start a new one. – John Smith May 18 '16 at 01:46

1 Answers1

0

I recently answered someone regarding Tables and the amount of effort and work you have to put in to get very basic functionality (sorting,searching,pagination).

Why re-invent the wheel if there is a perfectly great library for you to use: Angular-datatables

I posted a complete solution here for you to use pulling data from a json source: Ng-repeat trying to create a counter index

In your case you would need to go through the Server side processing documentation on Datatable's site to correctly format the data: https://datatables.net/manual/server-side

Community
  • 1
  • 1
johan
  • 998
  • 6
  • 20