rowGroup when adding a column does not consider the negative numbers.
rowGroup when adding a column does not consider the negative numbers.
rafael_black
Posts: 12Questions: 1Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
https://debug.datatables.net/igeyub
Hello my name is Rafael I'm from the south of Brazil and I'm new here on the forum and I hope to be complying with all the rules.
rowGroup when adding a column does not consider the negative numbers, it adds everything instead of decreasing when it has negatives. Does not show error message.
This discussion has been closed.
Answers
The
footerCallback
is not part of the RowGroup extension. Guessing the problem is with your regex expressionb.replace(/[^\d]/g, '')
. I think this is replacing any non-digit with''
removing the-
you might have. If this doesn't help please provide a test case showing the issue with an example of your data so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
EDIT: Does the
intVal()
function not work for you?Kevin
Hello @kthorngren thanks for the answer I'm having a little trouble creating a test case but I'm trying. Sorry for the question where would I use intVal() ?
See this example for how intVal() is used.
Kevin
@kthorngren no friend the intVal() doesn't work for me.
In order to help we will need to see a test case with an example of the data you are trying to sum. You can start with this:
http://live.datatables.net/
You can change it to use Javascript data like this example or you can just modify one of the columns in HTML. You can remove most of the rows to make it easier. In addition to the data all we need os your
footerCallback
code.Kevin
@kthorngren i am trying to make a test case i cant get the feedback.
http://live.datatables.net/conuqefa/1/edit
You have
<tfooter></tfooter>
instead of<tfoot></tfoot>
. Changed that and used the inVal() function, replacing your regex replace, as shown in this example.http://live.datatables.net/yibufigi/1/edit
Kevin
@kthorngren In the original code it still doesn't work.
You are asking about the
footerCallback
which is expected to update the table'sfooter
. But theTotal
you are showing in the screenshot is in the table. I suspect it is a total calculated byrowGroup.endRender
. Looks like you are doing the same thing in that function with the regex. Just remove the replace statement.Kevin
good @kthorngren morning yes my problem is in rowGroup and not in the final sum of the footer my problem is in the sum of the lines and my code is divided by groups. I've already adjusted the rowGroup function and did as you told me to do in footerCallback I replaced the regex function in rowGroup but I still don't get the sum of the negatives.
I added the rowGroup library to your example:
http://live.datatables.net/yibufigi/2/edit
I update the
rowGroup.endRender
function to do the same thing as thefooterCallback
by addingintVal
into the function and calling it in the reduce function.Kevin
@kthorngren I'm getting this error when putting it the way you suggested it at first has no empty return.
You have
console.log(valor)
in the function. What is the output?The intVal function should be returning numbers. Have you debugged where the NaN might be coming from?
Are you using
columns.render
or something else to generate the values for that column? Or is that the actual data from the server?Can you update the test case to show the problem or post a link to your page so we can help debug?
Kevin
@kthorngren the data comes from a database query I do in my controller I use Laravel and send the values ββto my view and do a for each on the table. I don't use collumns.render I use columnDefs and I do a grouping and I leave the column I grouped invisible. My intention is to add the lines of each group and then do a total sum in the footer. but my problem is in rowGroup. the console.log(value) I put to debug the variable return when the regex function is by default the code works and console.log shows the result of each group.
Seems strange that the console.log statement shows the results of each group - not sure if they are right or not - but that the
rowGrou.endRender
display isNaN
. They are using the same variablevalor
.Please post a link to a test case replicating the issue so we can help debug.
Kevin
@kthorngren a test access follows. Use the test user and password 0123456, go to the ControlleriaTi/Expenses side menu, the test query is being carried out between Start 06/01/2021 End 06/21/2021 Cost Center 01204 - INFORMATION TECHNOLOGY.
http://portal.bomprincipioalimentos.com.br/
I'm not sure what the
test user
is. I'm unable to login.Kevin
@kthorngren
I pulled this data but there aren't any negative numbers. Looks like summing the positive numbers works. Do you have a set of data with negative numbers or something that isn't working correctly?
It looks like you are loading datatables.js multiple times (lines 3106 3116 and 3123) and rowGroup.js in 3117 and 3124. You should load these only once. Please review all your CSS and JS libraries you are loading to make sure they are only loaded once.
Kevin
@kthorngren the correct date for search is Start 06/21/01 End 06/21/30. I sent you the date before in Brazil format. the search date that appears negative numbers is for the entire month of June.
Looks like you are still using
return a + b.replace(/[^\d]/g, '') * 1;
instead of callingintVal
:Kevin
Good morning @kthorngren I managed to solve my problem in another way I created 2 columns one with positive and negative numbers I left them invisible and put the result in the value column and divided the positive by 100 and the negative by 100 and subtracted the 2 and it worked. @kthorngren thank you so much for your help and your time to help me.