Static text for server side column presentation

Static text for server side column presentation

mconstablemconstable Posts: 4Questions: 1Answers: 0

I want the return data to include a column with some static content (like "/" below) and even though this works I get a warning in my php-errors.log with "PHP Notice: Undefined index: in /path/to/server-side.php" so I suspect I am doing this incorrectly. Would anyone have a suggestion how to provide some static content per column?

            $columns = [
                ['dt' => 0,  'db' => 'domain'],
                ['dt' => 1,  'db' => 'num_aliases'],
                ['dt' => 2, formatter' => function($d) { return '/'; } ],
                ['dt' => 3,  'db' => 'aliases'],

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Currently the demo SSP script doesn't have that ability. It will always lookup a database column for each entry in the array. If you want it to not do that, you'd need to modify the script.

    Allan

  • mconstablemconstable Posts: 4Questions: 1Answers: 0

    Heh, oh boy, that's going to be fun. I was hoping I wouldn't have to touch the SSP class.

    Somewhat related, in the example above, is there a way to pass in the tables primary key "id" without requiring it as a rendered table column yet still have access to it as $row['id'] ?

  • mconstablemconstable Posts: 4Questions: 1Answers: 0

    FWIW I think I have this working by putting some exceptions in the SSP class methods including being able to add an "invisible" column if dt=null so that, in this example, $row['id'] is available inside the anon formatter function.

                $columns = [
                    ['dt' => null, 'db' => 'id'],
                    ['dt' => 0,  'db' => 'domain'],
                    ['dt' => 1,  'db' => 'num_aliases'],
                    ['dt' => 2,  'db' => null, 'formatter' => function() { return '/'; } ],
                    ['dt' => 3,  'db' => 'quota_aliases'],
                    ['dt' => 4, 'db' => 'active', 'formatter' => function($d, $row) {
                        return '
                          <a href="?action=delete&i=' . $row['id'] . '" title="Remove Vhost" onClick="javascript: return confirm(\'Are you sure you want to remove: ' . $row['domain'] . '?\')"></a>';
                    }],
    
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    is there a way to pass in the tables primary key "id" without requiring it as a rendered table column yet still have access to it as $row['id'] ?

    Yes, just don't define a column in the Javascript / HTML that uses it. It will still be in the JSON data, but not displayed.

    Allan

  • mconstablemconstable Posts: 4Questions: 1Answers: 0

    Doh, thanks for that. I see an example somewhere of ['db' => 'id'] but now that I've added some logic to detect the ['db' => 'id', 'dt' => null] case I get an error if I remove my 'dt' => null. One thing that might be useful in general is that I managed to get column order sort working by using this in ::order($request, $columns)...

    $columnIdx = array_search($requestColumn['data'], array_column($columns, 'dt'));
    

    instead of the original...

    $dtColumns = self::pluck($columns, 'dt');
    $columnIdx = array_search($requestColumn['data'], $dtColumns);
    
This discussion has been closed.