DataTable Editor column data format

DataTable Editor column data format

bbrindzabbrindza Posts: 300Questions: 69Answers: 1

I am using DataTable Editor with ssp. In my DB2 table I have some numeric columns the contain values of 0.0.

However my ssp returns the JSON data to the front end as .0.

{"data":[{"data":"DT_RowId":"row_1","BD$01":".0"}]}

Where and how should I format .0 as 0.0?

<?php
session_start();

$salespersonNumber=trim($_REQUEST['salespersonNumber']);
$customerNumber=trim($_REQUEST['customerNumber']);
$productNumber=trim($_REQUEST['productNumber']);

// DataTables PHP library
require( $_SERVER['DOCUMENT_ROOT']."/DataTables_Editor/php/DataTables.php" );
  
// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
// Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'NWFF.PROJLOC', array('PKLOC', 'PKRGNO', 'PKSLNO', 'PKCUST', 'PKPROD' ))
   
        ->debug(true)
        
        ->fields(
       
            Field::inst( 'BD$01' ) 
            ->validator( 'Validate::notEmpty' )
            ->validator( 'Validate::numeric' )
   
    )     
        ->where( function ( $q ) use ( $salespersonNumber, $customerNumber, $productNumber ) {
            $q->where( 'PKRGNO', $salespersonNumber );
            $q->where( 'PKCUST', $customerNumber );
            $q->where( 'PKPROD', $productNumber );
        } )
        
    ->process( $_POST )
    ->json();

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    As a numeric value 0.0 === 0. So yes, I would expect every database and programming language, not just DB2, to do that.

    0.0 is really a formatting decision to show the number with one decimal point (note that it does not add any additional information to the value).

    If you want to format the data for that column to have once decimal place shown, use the number formatter on the client-side.

    Allan

  • bbrindzabbrindza Posts: 300Questions: 69Answers: 1

    That's what I was looking for Thanks for the hookup.

Sign In or Register to comment.