Reputation: 9084
I am trying to do the following but I am not sure how to do it. I have a grid (like excel) where the user will enter information. The grid has columns like "empno", "paycode", "payrate", "hours" etc. The user will enter a separate record in the grid for each paycode for each employee in the system. so the grid will look like the following
empno paycode payrate hours 1 R 25.00 40.00 2 R 12.00 40.00 3 R 15.00 18.00 1 v 25.00 12.00 2 PTO 25.00 18.00
Below this grid I will have two grids. One that displays "Employee totals" and one that displays "Totals by paycode". so as the user enters the data in the grid, I am planning to add / update the values into a two dimensional array. Then when the user clicks on a particular record on the grid, I will read the empno from that record and display the employee totals by binding the array to the html table. As you can see the data entered by the user might not be in the order of empno. The user might first enter the data for paycode "R", then paycode "V" etc.
Please let me know your ideas.
Upvotes: 1
Views: 2112
Reputation: 5003
Why don't you just store it in a JavaScript object that's keyed off of your employee numbers. For instance...
var emps = {};
emps['1'] = [
{
empno : '1',
paycode : 'R',
payrate : '25.00',
hours : '40.00'
},
{
empno : '1',
paycode : 'G',
payrate : '30.00',
hours : '10.00'
}
];
function getEmp( empno ) {
if ( emps[empno] && typeof emps[empno] === "object" ) {
return emps[empno];
} else {
return false;
}
}
function addRecord( record ) {
if ( !emps[record.empno] || typeof emps[record.empno] !== "object" ) {
emps[record.empno] = [];
}
emps[record.empno].push( record );
}
Upvotes: 1
Reputation: 7212
It sounds like you want to loop through the input fields, and update the Employee total fields.
If the number of employee number records is unknown, I would use an id for each input similar to this: id=empno_x where x is a unique ID for each staff member. You can then use jquery to get the values using:
//Loop through all employee number input fields
$(":input[id^='empno_']").each function(){
//Do whatever you need to do with the data (add it to an array etc)
});
So you would do that for the empno, paycode, payrate, and hours fields.
Once you have captured the data being input, it's just a matter of manipulating the HTML using Jquery.
Hope this helps!
Upvotes: 0