Make a counter with conditional

Make a counter with conditional

jdiaz11jdiaz11 Posts: 6Questions: 5Answers: 0

Hello I have a question about how to make a counter, currently I have data that show me the purchase order in a column and if you do not have one then I make a conditional with laravel template blade to show me a dash "-" or subtraction sign, now I want to make me only count the data that have a purchase order.
Example
Number / Purchase order
1 / abc1
2 / -
3 / -
4 / abc2

con esto código realizo el conteo de todos los datos como podría adaptarlo para que haga que solo me cuente los que tienen una orden de compra
var contador_oc = table.column(24).rows().count();
$("#counta_oc").text((+contador));

I leave the link where I detail better my doubt:

https://stackoverflow.com/questions/72427917/make-a-counter-with-conditional-in-datatables

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    edited May 2022

    Since you have server side processing enabled, serverSide: true you will only be able to count the rows on the page displayed. With server side processing the client only has the rows being displayed on the page.

    You can use rows() with the row-selector as a function to eliminate the rows that have a dash. You can use the count() API to get the count of rows return from the rows() API.

    Otherwise, to perform the calculation over all the rows you will need to perform the calculation server side and return it as part of the JSON response.

    Kevin

Sign In or Register to comment.