My sort don't work with my numbers in the server_processing. Why ?

My sort don't work with my numbers in the server_processing. Why ?

jytestjytest Posts: 26Questions: 0Answers: 0
edited March 2013 in General
Hi,

Can you help me ?

I use the jquery datatables with server_processing.
This reminds me server_processing in datatables
numbers (or words?) with the ',' separator for decimal.
[code]
$ inter = trim ($ aRow ['carat']);
$ row [] = number_format ($ inter, 2, ',', '');
[/code]

When I click on the arrows ascending and descending,
sorting does not occur in the numbers method, but the method texts.
ex. 10.01> 9.99 (in numbers)

How make it work with my numbers?

Thanks for your help.
Best regards.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Sorting in SSP mode is done by the server. Are you using an SQL database? That is what should be doing the sorting.

    Allan
  • jytestjytest Posts: 26Questions: 0Answers: 0
    edited March 2013
    Yes, the server_processing is here :
    [code]
    <?php
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * libellés types
    * 0 = forme
    * 3 = taille
    * 4 = couleur
    * 5 = pureté
    * 6 = poli
    * 7 = symetrie
    * 10 = fluo
    */
    $libelle = array();
    $libelle[1] = array ("", "Rond", "Princesse", "Emeraude", "Radiant", "Ovale", "Poire", "Marquise", "Coeur", "Asscher CS");
    $libelle[4] = array ("D", "E", "F", "G", "H", "I", "J", "K");
    $libelle[3] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
    $libelle[5] = array ("IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "SI3", "I1");
    $libelle[6] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
    $libelle[7] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
    $libelle[10] = array ("Sans", "Très légère", "Légère", "Faible", "Moyenne", "Forte", "Très forte");
    $libelle[12] = array ("Pointue", "Très petite", "Petite", "Moyenne", "Large");
    $nbcouleur = count($libelle[4])-1;
    $nbtaille = count($libelle[3])-1;
    $nbpurete = count($libelle[5])-1;
    $nbpoli = count($libelle[6])-1;
    $nbsymetrie = count($libelle[7])-1;
    $nbfluo = count($libelle[10])-1;
    $nbcolette = count($libelle[12])-1;

    $swColonne = array();
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    /* Array of database columns which should be read and sent back to DataTables. Use a space where
    * you want to insert a non-database field (for example a counter or static image)
    */
    $aColumns = array();
    $aColumns [] = 'item_id'; /* 00 */
    $aColumns [] = 'cut'; /* 01 */
    $aColumns [] = 'carat'; /* 02 */
    $aColumns [] = 'cut_grade'; /* 03 */
    $aColumns [] = 'color'; /* 04 */
    $aColumns [] = 'clarity'; /* 05 */
    $aColumns [] = 'polish'; /* 06 option11 */
    $aColumns [] = 'symmetry'; /* 07 option12 */
    $aColumns [] = 'depth'; /* 08 option13 */
    $aColumns [] = 'table'; /* 09 option14 */
    $aColumns [] = 'fluo_intensity'; /* 10 option15 */
    $aColumns [] = 'price_per_carat_ht'; /* 11 option16 */
    $aColumns [] = 'culet_size'; /* 12 option17 */
    $aColumns [] = 'length_width'; /* 13 option18 */
    $aColumns [] = 'delay'; /* 14 */
    $aColumns [] = 'total_price_ht'; /* 15 */
    $aColumns [] = 'item_id'; /* 16 */

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "item_id";

    /* DB table to use */
    $sTable = "diamant_data";

    /* Database connection information */
    $gaSql['user'] = "***";
    $gaSql['password'] = "***";
    $gaSql['db'] = "***";
    $gaSql['server'] = "***";


    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );

    mysql_set_charset( 'utf8' );


    /*
    * Paging
    */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
    intval( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    $sOrder = "";
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    unset ($mesures);
    $row = array();
    $comparer = trim($aRow[ 'item_id' ]);
    $row[] = " ";
    $row[] = trim($aRow[ 'cut' ]);
    $inter = trim($aRow[ 'carat' ]);
    $row[] = number_format($inter, 2, ',', ' ');
    $row[] = trim($aRow[ 'cut_grade' ]);
    $row[] = trim($aRow[ 'color' ]);
    $row[] = trim($aRow[ 'clarity' ]);
    $row[] = trim($aRow[ 'polish' ]);
    $row[] = trim($aRow[ 'symmetry' ]);
    $inter = trim($aRow[ 'depth' ]);
    $row[] = number_format($inter, 2, ',', ' ');
    $inter = trim($aRow[ 'table' ]);
    $row[] = number_format($inter, 2, ',', ' ');
    $row[] = trim($aRow[ 'fluo_intensity' ]);
    $inter = trim($aRow[ 'price_per_carat_ht' ]);
    $inter = trim($aRow[ 'length_width' ]);
    $row[] = number_format($inter, 2, ',', ' ');
    $row[] = trim($aRow[ 'delay' ]);
    $inter = trim($aRow[ 'total_price_ht' ]);
    $row[] = number_format($inter, 2, ',', ' ');
    $row[] = "Détails";
    $output['aaData'][] = $row;
    }

    echo json_encode( $output );
    ?>
    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Well if your SQL is string sorting, I guess it is a string data type?
  • jytestjytest Posts: 26Questions: 0Answers: 0
    And then, how to get a sorted array on the client? Can you help me? I am desperate to get there! Help me please.
  • jytestjytest Posts: 26Questions: 0Answers: 0
    Warning! 10,45 > 9,95, for me ! How does it ?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    If you want it to be sorted on the client-side, disable server-side processing.

    Allan
  • jytestjytest Posts: 26Questions: 0Answers: 0
    edited March 2013
    Ok,
    Thanks but how use the datatables with 150,000 items ?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    With server-side processing. Just make sure that your SQL can do a numeric sort on the data. That's nothing to do with DataTables itself.

    Allan
  • jytestjytest Posts: 26Questions: 0Answers: 0
    Thanks
This discussion has been closed.