user2338925
user2338925

Reputation:

Get the total count of multiple values in a table row

I'm using doctrine and php for data query from mysql table.My table looks like this Completed Overdue Ongoing

I'm using some code in action to render datas to the table.My question is is it possible to use Javascript to get the total count of each rows?This is the complete table with some datas enter image description here

I want to count the datas in "Completed","Overdue","Ongoing" columns.Is it possible with Javascript?

Upvotes: 0

Views: 277

Answers (3)

Farshad
Farshad

Reputation: 1485

simply you can count number of ',' in each columns for completed / overdue or ongoing

you can use this code for find number of occurrence for specific character in javascripts

var temp = "This is a string. is";

// the g in the regular expression says to search the whole string 
// rather than just find the first occurrence
var count = temp.match(/is/g);  
alert(count.length);

Upvotes: 1

hunzter
hunzter

Reputation: 598

If I understand it correctly then you want to count B-12, B17... in those columns. Yes it's possible with javascript. You can do the following steps:

  1. Traverse to all rows of the table(except for the header)
  2. Get content of corresponding cell(index is 4 in this case for 'Completed')
  3. Split the content with delimiter is ',', out put is an array of each item(i.e: B-2)
  4. Get array length => this is your desire output.

You will have to research about what called DOM(Document Object Model) and how to use Javascript to handle with it. I suggest you to use Javascript library like [http://jquery.com/][1] to make thing easier

Upvotes: 0

florin.prisecariu
florin.prisecariu

Reputation: 422

You should put some code for a good answer

So, it is possible if you put each task completed in a different <span>, for example lets asume the "Completed" column has the class .completed: for each row, count the completed:

$('tr').each(function(key, item){
   var completed = $(item).find('td.completed').find('span').length;
   //do something with the completed
})

Upvotes: 0

Related Questions