I have created a sinple table view here: hidden link
On the bottom of the page I want to display some calculated output.
Number of posts is displayed with the shortcode [wpv-found-count]
Is it possible to display number of posts based on condition in the columns Branninstruks, Rømningsveier, Slokkerutstyr and Møteplass?
(See bottom of the page for the conditions I want to display)
Your custom jQuery code count content that contains in a row. I need to count the content that contains in a column. In my test page, the numbers should be like this:
Number of posts with Branninnstruks = "Ja": 6
Number of posts with Rømningsveier = "Ja": 7
Number of posts with Slokerutstyr = "Ja": 7
Number of posts with Møteplass = "Ja": 7
Is it possible with columns and custom jQuery code count ?
You should add your lines where you added the static lines within your Loop Editor as given under:
<div class="branninnstruks"> Number of posts with Branninnstruks = "Ja": <div class="count"> 0 </div> </div>
<div class="romningsveier"> Number of posts with Rømningsveier = "Ja": <div class="count"> 0 </div> </div>
<div class="slokerutstyr"> Number of posts with Slokerutstyr = "Ja": <div class="count"> 0 </div> </div>
<div class="Moteplass"> Number of posts with Møteplass = "Ja": <div class="count"> 0 </div> </div>
Hello Rune, Minesh is on a vacation for a couple of days. If you don't mind I'll continue with you on this thread.
I would suggest that you add a special class to each column, then you can use jQuery to count the instances. Check this screenshot, where I added a class "bran" in the browser dev tools to the columns "Branninstruks" and how it calculated the instances with the following code hidden link
Does it make sense to you? If not, please allow me temporary access to the admin area and I'll prepare an example for you. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
The counters are put inside a <div> tag which is by default displayed as a block(in its own row or line), I would use an inline tag such as <span> tags. hidden link
Would you like to display the counts and the scores or only the scores? Where do you want to display them? Can you add an example of how it should be?
In the meantime, I would like to explain the following:
- The count can be done using $(".js-wpv-view-layout table .bran:contains(Ja)").length.
- The total number can be done using $(".js-wpv-view-layout table .bran").length.
- The calculation and getting 2 decimals after the comma can be done using this ( (count / total) *100 ).toFixed(2)
Let me know how do you want to display the results(count and/or score) and I'll help with it.