Okay
  Public Ticket #2640519
Set Blank cells values to 0 in specific Columns
Closed

Comments

  •  1
    Joshua Byerly started the conversation

    We are pulling data through SQL Query from our MSSQL Server. Some values are required to be left as null on the SQL Server side, but that breaks the WPDATATABLES Charts.

    Can you recommend a way to set blank values to be shown as 0 in specific columns on the wpdatatables side?

    We have them currently set to Float, but have tried Integer with no luck. They still show as blank.

  •  2,507
    Aleksandar replied

    Hello Joshua

    That is an issue we've been dealing with, because integer and float columns cannot have anything other than numbers in them, the plugin is treating an empty cell as "0"

    I can try and help you out, but you have to make some changes in code in file :

    /wp-content/plugins/wpdatatables/source/class.wpdatachart.php around line 1631:

    case 'int':
       $return_data_row[] = (float)$row[$columnKey];
     break;
       case 'float':
         if ($decimalPlaces != -1){
           $return_data_row[] = (float)number_format(
             (float)($row[$columnKey]),
             $decimalPlaces,
             '.',
             $thousandsSeparator ? '' : '.');
           }else {
               $return_data_row[] = (float)$row[$columnKey];
           }
    break;

    and replace it with this

    case 'int':
                                    if (is_null($row[$columnKey])){
                                        $return_data_row[]= null;
                                    }else{
                                        $return_data_row[] = (float)$row[$columnKey];
                                    }
                                    break;
                                case 'float':
                                   if ($decimalPlaces != -1) {
                                       if (is_null($row[$columnKey])) {
                                           $return_data_row[] = null;
                                       }else {
                                           $return_data_row[] = (float)number_format(
                                               (float)($row[$columnKey]),
                                               $decimalPlaces,
                                               '.',
                                               $thousandsSeparator ? '' : '.');
                                       }
                                   } else {
                                       if (is_null($row[$columnKey])) {
                                           $return_data_row[] = null;
                                       }else {
                                           $return_data_row[] = (float)$row[$columnKey];
                                       }
                                   }
                                    break;

    With these changes you will get charts like on the first screenshot below.

    If you want to make charts like on screenshot #2 you have to use wpdatachart callbacks and insert that on page where your chart is.

    <script type="text/javascript">
    jQuery(window).on('load',function(){
        if( typeof wpDataChartsCallbacks == 'undefined' ){ wpDataChartsCallbacks = {}; }
            wpDataChartsCallbacks[39] = function(obj){
                    obj.options.plotOptions.series= {connectNulls: true};
                }
    });
    </script>

    One more thing you have to change in this callback number 39 in (wpDataChartsCallbacks[39]) to id of the chart that you use on the page.

    This will be overwritten on next update so you have to come back here and do it again.

    1539290246.png
    3942732156.png

    Also, you should disable "Use minified wpDataTables Javascript" slider in main settings of wpDataTables/Custom JS and CSS:

    2541706081.png

    And also clear your cookies.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Joshua Byerly replied

    Thank you for the response Aleksandar.

    I have implemented the changes as suggested and we are still running into the issue. I have attached an image showing the issue we are running into. It happens on all chart render engine types.

    7676014487.png

    If there is a column that has a blank cell, it just does not calculate correctly. The chart is calculating all the other grouped data fine. I am stumped as to what is causing it. If the null cells are actually seen as "0" then I would think the way we are using the charts should work out fine then.

    If we use the filters to filter data that does not include a possible blank cell, the charts work fine.

  •  2,507
    Aleksandar replied

    Hi again Joshua

    Did you disable "Use minified wpDataTables Javascript" slider in main settings of wpDataTables/Custom JS and CSS? This is the most common mistake.

    If you did, and it's still not working fine, please provide me a temporary WP-admin login for your site where this happens, so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. We do not interfere with any data or anything else except for the plugin (in case that’s a production version of the site), and of course we do not provide login data to third party. Also, make sure to tell me what's the table and chart ID, so I know where to look.

    You can write credentials here just check Private Reply so nobody can see them except us.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Joshua Byerly replied

    Yeah, disabled the minified tables javascript.

    Unfortunately the site is completely internal, so there is no external access, darn. I was hoping it was something simple, like your original message heh.

    Guess I am going to look more into SQL Query. See if there is some way for the query to import null values it see's with '0'. I tried this previously, but it broke the table and I had to go into phpmyadmin and fix all the column positions, since any change to the query seems to just break the tables.

  •  2,507
    Aleksandar replied

    Hey Joshua.

    Sorry to hear that didn't work.

    I don't know what you tried with the query, but take a look at this thread. It looks simple enough.

    I just tried it, and it works for me:

    5407524532.png

    So, in wpDataTables, if I use SELECT * FROM null_integer, it comes out like this:

    7077730759.png

    But if I use this query:

    SELECT Name, 
            IFNULL(Numbero,0) AS Numbero, 
            IFNULL(floato,0) AS Floato
    FROM null_integer
    

    It comes out like this:

    4616385702.png

    If you see some columns missing after applying the query above (with IFNULL), disable server-side processing; save the table, and then enable server-side processing again (if you don't need it, you can leave server-side processing off). Please let me know if that helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Joshua Byerly replied

    Thank you, looks like I got it working now with using ISNULL.

    Since it is a query to MSSQL Server, the syntax is ISNULL, instead of IFNULL.

    Thank you very much!

  •  2,507
    Aleksandar replied

    You're welcome, Joshua

    Glad I could be of service!

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables