DataTable Sort Issue

I’m populating a DataTable with some data that I want to sort by the column ‘label’ as the order the table is populated in is not being maintained when I render the table (as either a table or evolution graph)

To apply the sort I’m currently using the following method in my API method before returning the table to the controller:

    $dataTable->filter('Sort', array('label', 'desc', true, true));

However, this seems to behave strangely. Changing the sort order makes a different, but the resulting order is neither truly ascending or descending, am I doing something wrong?

Also, is anyone able to explain why the original population order isn’t maintained?

Hey,

This might come a little late but I ran into the same problem and solved it by using

$view = ViewDataTableFactory::build(‘newtable’, ‘MyPlugin.apiMethod’, ‘MyPlugin.controllerMethod’);
$view->requestConfig->disable_generic_filters=true;

This should keep Piwik from reordering the array.

Thank you hahazombies! It helped me so much! I could not understand why piwik always reorder my graph, thanks again! :wink:

I had to do this:

$archive   = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable(Archiver::XXX_RECORD_NAME);
$array     = $dataTable->getRows();
for ($i=0; $i < count($array); $i++) {
  $array[$i]['readings'] = intval($array[$i]['readings']);
}
$dataTable_ = new DataTable();
$dataTable_->addRowsFromArray($array);
$dataTable_->queueFilter('Sort', array('column'));
return $dataTable_;