It is possible to specify a natural sorting (see php.net/natsort for details).
Inheritance: extends Piwik\DataTable\BaseFilter
Example #1
0
 /**
  * Test to sort by visit
  *
  * @group Core
  */
 public function testFilterSortNumeric()
 {
     $idcol = Row::COLUMNS;
     $table = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)));
     $table->addRowsFromArray($rows);
     $expectedtable = new DataTable();
     $rows = array(array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'google', 'nb_visits' => 897)));
     $expectedtable->addRowsFromArray($rows);
     $expectedtableReverse = new DataTable();
     $expectedtableReverse->addRowsFromArray(array_reverse($rows));
     $filter = new Sort($table, 'nb_visits', 'asc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtable));
     $filter = new Sort($table, 'nb_visits', 'desc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtableReverse));
 }
Example #2
0
 public function test_sortingArrayValues_doesNotError()
 {
     $table = new DataTable();
     $table->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'ask', 'count_array' => array(100, 1, 2))), array(Row::COLUMNS => array('label' => 'nintendo', 'count_array' => array(0, 'hello'))), array(Row::COLUMNS => array('label' => 'yahoo', 'count_array' => array(10, 'test')))));
     $tableOriginal = clone $table;
     $filter = new Sort($table, 'count_array', 'desc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($tableOriginal, $table));
 }