Problem with sort column on table

Hi all

Maybe you will have ideas with my problem. I wrote some plugin, which uses its own db table. On view it’s simple table. When i click on column, out request with params

action=pageIntent
controllerActionCalledWhenRequestSubTable=
date=2013-04-15
enable_sort=1
filter_offset=0
filter_only_display_idgoal=-1
filter_sort_column=Index
idSite=104
module=UserProfiles
period=year
totalRows=100
viewDataTable=table

Response is returned with sorted table, it’s ok. But table on user brouser don’t change. In console js error ‘uncaught exception: Syntax error, unrecognized expression: #’. What could it be?

not sure, can you check the response has the right DIV id/classes (compared to the core ones) ?

We will definitely make this better/easier in Piwik 2.0 in next few months.

I looked my response and DIV (like

) is absent. Maybe you know any exampe, how to get sorted data via ajax.

I’m using this code:

function pageReport()
{
    $view = Piwik_View::factory('index');
    $view->profilesHeader = Piwik_Translate('tmpProfilesAdm_SubMenuNameIntent');

    $objPageTable = Piwik_ViewDataTable::factory('table');
    $objPageTable->init($this->pluginName, __FUNCTION__, "tmpProfiles.getReport");

    $objPageTable->setSortedColumn('ID', 'asc');
    $objPageTable->setLimit(200);
    $objPageTable->disableShowAllColumns();
    $objPageTable->disableExcludeLowPopulation();
    $objPageTable->disableSearchBox();

    $view->profilesTable = $this->renderView($objPageTable, true);
	
echo $view->render();

}

problem was resolved.

How?

I did not understand in detail. In first version in controller used code like this


//call from client
function getPageReport()
{
    $view = Piwik_View::factory('index');

    //table
    $view->profilesTable = $this->getPageTable('getReportUser', array(
        'profile',
        'visitors',
        'Index'
    ));
    echo $view->render();
}		

function getPageTable($action, array $headers)
{
    $objPageTable = Piwik_ViewDataTable::factory('table');
    $objPageTable->init($this->pluginName, __FUNCTION__, "Report.".$action);

    //table
    $this->fTranslateHeaders($headers);

    foreach($headers as $k => $header)
        $objPageTable->setColumnTranslation('Column-'.$k, $header);

    $objPageTable->setSortedColumn('1', 'asc');
    $objPageTable->setLimit(200);
    $objPageTable->disableShowAllColumns();

    return $this->renderView($objPageTable, true);
}

In second version using code like this


//Controller

//call from client
public function getPageInterest($fetch = false) {
    $view = $this->getPageIntentView(__FUNCTION__, 'getEntryPageInterestSubDataTable');
    $this->configureViewInterest($view);
    $this->configureViewActions($view);
    return $this->renderView($view, $fetch);
}

protected function getPageIntentView($currentAction, $controllerActionSubtable)
{
    $view = Piwik_ViewDataTable::factory();
    $view->init($this->pluginName,
        $currentAction,
        'Report.getReportIntent',
        $controllerActionSubtable );
    $view->setColumnTranslation('label', Piwik_Translate('Report_ColumnPageURL'));
    return $view;
}	


//API
public function getReportIntent($idSite, $period, $date, $segment = false, $columns = false)
{
    ...

    try{
        $result = Piwik_fetchAll("
        SELECT
            ....
        "
            , array($idSite)
        );

        $this->fTranslateColumn($result, 'Interest');
    }
    catch(Exception $e){
        $result = array();
    }

    $dataTable = $this->getReportTable($result);

    return $dataTable;
}

public function getReportTable(&$data)
{
    $dataTable = new Piwik_DataTable();

    foreach($data as $row)
    {
        $dataRow = new Piwik_DataTable_Row();

        $i = 0;
        foreach($row as $column)
            $dataRow->addColumn('Column-' . $i++, $column);

        $dataTable->addRow($dataRow);
        $dataRow->__destruct();
    }

    return $dataTable;
}