rowGroup when adding a column does not consider the negative numbers.

rowGroup when adding a column does not consider the negative numbers.

rafael_blackrafael_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.

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited August 2021

    The footerCallback is not part of the RowGroup extension. Guessing the problem is with your regex expression b.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

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    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() ?

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    See this example for how intVal() is used.

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @kthorngren no friend the intVal() doesn't work for me.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited August 2021

    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

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @kthorngren i am trying to make a test case i cant get the feedback.

    http://live.datatables.net/conuqefa/1/edit

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited August 2021

    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

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @kthorngren In the original code it still doesn't work.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    You are asking about the footerCallback which is expected to update the table's footer. But the Total you are showing in the screenshot is in the table. I suspect it is a total calculated by rowGroup.endRender. Looks like you are doing the same thing in that function with the regex. Just remove the replace statement.

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    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.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    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 the footerCallback by adding intVal into the function and calling it in the reduce function.

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @kthorngren I'm getting this error when putting it the way you suggested it at first has no empty return.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited August 2021

    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

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @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.




  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    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 is NaN. They are using the same variable valor.

    Please post a link to a test case replicating the issue so we can help debug.

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @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/

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I'm not sure what the test user is. I'm unable to login.

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0
  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Start 06/01/2021 End 06/21/2021 Cost Center 01204 - INFORMATION TECHNOLOGY.

    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

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    @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.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Looks like you are still using return a + b.replace(/[^\d]/g, '') * 1; instead of calling intVal:

            rowGroup: {
                startRender: null,
                endRender: function(rows, group) {
                    // Remove the formatting to get integer data for summation
                    var intVal = function(i) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '') * 1 :
                            typeof i === 'number' ?
                            i : 0;
                    };
                    var valor = rows
                        .data()
                        .pluck(4).reduce(function(a, b) {
                            console.log(b);
    
                            return a + b.replace(/[^\d]/g, '') * 1;
    
                        }, 0);
    
    
                    valor = valor / 100;
                    valor = $.fn.dataTable.render.number(',', '.', 2, 'R$ ').display(valor);
                    // console.log(valor);
                    return $('<tr/>')
                        .append('<td></td>')
                        .append('<td></td>')
                        .append('<td><center><strong style="color: blue;">Total</center></td>')
                        .append('<td><center><label><strong style="color: blue;">' + valor + '</strong></label></center></td>');
    
                },
                dataSrc: groupColumn
            },
    

    Kevin

  • rafael_blackrafael_black Posts: 12Questions: 1Answers: 0

    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.

Sign In or Register to comment.