Which is better, searching in javascript or database?

I have a grid (employees grid) that will say 1000-2000 lines. I display the employee name and department in the grid. When I get data for the grid, I get other details for the employee (Date of birth, location, role, etc.), Thus, the user has the ability to edit the employee data. when he clicks on the edit, I need to display other employee data in a popup window. since I saved all the data in JavaScript, I am looking for a specific identifier and display all the details. so the code will look like

function getUserDetails(employeeId){
  //i store all the employeedetails in a variable employeeInformation while getting //data for the grid. 
   for(var i=0;i<employeeInformation.length;i++){
        if(employeeInformation[i].employeeID==employeeId){
              //display employee details.
        }
   }
}

the second solution would be like passing employeeid to the database and getting all the information for the employee. The code will be like

function getUserDetails(employeeId){
       //make an ajax call to the controller which will call a procedure in the database
       // to get the employee details
       //then display employee details
    }

, , , , 1000-2000 . , JavaScript , .

:

. 4 500 ( ). , - . , , data-rowId , . , , employeeInfo. - .. $(this).attr('data-rowId') rowId employeeInfo [$ (this).attr('data-rowId')] , , employeeid employee, employeeid, rowid . . .

+3
4

AJAX . -

  • javascript - .
  • Javascript , .

Javascript . .

+1

JavaScript, , . , , . JavaScript . Ajax- .

0

HTML5? , , ? , - (http://www.w3schools.com/html/html5_webworkers.asp) , .

, , , , , - .

0

, .

, , .., , . , , - , , . , , .

A more pragmatic approach to this problem is to have your controller populate the client with only the specific data related to it, eliminating the need to search across many records. You can also get one object by making an ajax request to your server to retrieve the data. This provides double benefits by ensuring that you show the current state of the database, and are also much more optimized than anything you could ever write in JS.

0
source

All Articles