DataTables warning: table id=foo - Requested unknown parameter 'bar.name'

DataTables warning: table id=foo - Requested unknown parameter 'bar.name'

system.bonn@gmail.comsystem.bonn@gmail.com Posts: 28Questions: 4Answers: 1

Hi!

I am getting the error (warning) "DataTables warning: table id=foo - Requested unknown parameter 'bar.name'". This occurs, when a relation to a foreign table is NULL. But this is perfectionally reasonable. My entries in 'foo' can have a related 'bar' or not. The field bar_id is nullable and in this given case actually NULL.

Can I tell datatables. yes, that's ok, move on? An stop displaying these pup-pus?

TIA & cu,
ada

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @system.bonn@gmail.com ,

    Is this with serverSide, or with Editor? Could you post the server-side script, please, it would help to make suggestions.

    Cheers,

    Colin

  • system.bonn@gmail.comsystem.bonn@gmail.com Posts: 28Questions: 4Answers: 1

    Hi!

    This occurs with DataTables (only Datatables, not Editor) when I setup a table in laravel-datatables. If there is a relationship to another table (pos.group_id -> group.id), and the 'on-field' (pos.group.id) is NULL:

    class Phone extends Authenticatable
    {
      [...]
    
      public function group() {
        return $this->belongsTo('App\Group');
      }
    
      [...] 
    }
    

    And:

    class Group extends Model
    {
        public function phones() {
            return $this->has('App\Phone');
        }
    }
    

    PhonesDataTable.php:

                                    protected function getColumns()
                                    {
                                        return [
                                            [
                                             'data' => null,
                                             'defaultContent' => '',
                                             'className' => 'select-checkbox',
                                             'title' => '',
                                             'orderable' => false,
                                             'searchable' => false
                                            ],
                                            ['data' => 'id', 'title' => 'Id'],
                                            ['data' => 'group.name', 'title' => 'Gruppe'],
                                        ];
                                    }
    

    Please let me know, when you need further information.

    cu,
    ada

  • allanallan Posts: 63,192Questions: 1Answers: 10,412 Site admin
    Answer ✓

    Can I tell datatables. yes, that's ok, move on? An stop displaying these pup-pus?

    Yes - use columns.defaultContent to tell DataTables what to do if this is expected (i.e. you could set it to be an empty string).

    Allan

  • system.bonn@gmail.comsystem.bonn@gmail.com Posts: 28Questions: 4Answers: 1

    Thank, you!

    It works, although I prefered to solve it in the laravel model using 'withdefaults'.

    thx & cu,
    ada

This discussion has been closed.