/**
* Setup columns
*
* @access public
* @param string data callback function
*/
public function generate($table_data = NULL)
{
if (!$this->jq_template) {
return parent::generate($table_data);
}
$this->_compile_template();
$open_bak = $this->template['table_open'];
// prep the jquery template
$temp = $this->template['row_start'];
foreach ($this->column_config as $column => $config) {
$html = FALSE;
if (is_array($config)) {
$html = isset($config['html']) ? (bool) $config['html'] : FALSE;
}
// handle data of array('data' => 'content', 'attr' => 'value')
$temp .= '{{if $.isPlainObject(' . $column . ')}}';
$temp .= substr($this->template['cell_start'], 0, -1);
$temp .= '{{each ' . $column . '}}';
$temp .= '{{if $index != "data"}} ${$index}="${$value}" {{/if}}';
$temp .= '{{/each}}';
$temp .= '>';
$temp .= $html ? '{{html ' . $column . '.data}}' : '${' . $column . '.data}';
$temp .= '{{else}}';
$temp .= $this->template['cell_start'];
$temp .= $html ? '{{html ' . $column . '}}' : '${' . $column . '}';
$temp .= '{{/if}}';
$temp .= $this->template['cell_end'] . "\n";
}
$temp .= $this->template['row_end'];
$template = $temp;
// add data to our headings for the sort mechanism
$column_k = array_keys($this->column_config);
foreach ($this->heading as $k => &$heading) {
if (!is_array($heading)) {
$heading = array('data' => $heading);
}
if (!$this->column_config[$column_k[$k]]['sort']) {
$heading['class'] = 'no-sort';
}
$heading['data-table_column'] = $column_k[$k];
}
if (!$this->base_url) {
$this->base_url = $this->EE->cp->get_safe_refresh();
}
$jq_config = array('base_url' => $this->base_url, 'columns' => $this->column_config, 'template' => $template, 'empty_cells' => $this->empty_cells, 'no_results' => $this->no_results, 'pagination' => $this->pagination_tmpl, 'uniqid' => $this->uniqid, 'sort' => $this->sort, 'rows' => $this->raw_data);
$table_config_data = 'data-table_config="' . form_prep($this->EE->javascript->generate_json($jq_config, TRUE)) . '"';
$this->template['table_open'] = str_replace('<table', '<table ' . $table_config_data, $open_bak);
$table = parent::generate();
$this->template['table_open'] = $open_bak;
return $table;
}