editable Grid with total calculation vertically and horizontally when something in the column changes

i am assigned with a task to calculate the total of records vertically(column wise) and horizontally(row-wise) when a user makes any changes in the text boxes. i have attached a screenshot below. basically, the grid can have n no of rows(to be fetched from the db) but no of columns will remain same always. but for now i'm trying to make this happen with only static values. Future task: is to make paging happen in the same Grid.

somehow, i am able to solve it for horizontal calculations. but still struggling for vertical calculations.

  Discussion posts and replies are publicly visible