⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callbackColumn not working



blexis
  • profile picture
  • Member

Posted 12 March 2019 - 21:22 PM

I'm trying to use callbackColumn but every time I get an empty cell in the datagrid.

 

I'm using this code:

$crud->columns(array('ddl_name', 'ddl_title', 'ddl_address', 'new_col'));
$crud->displayAs(array('ddl_name' => 'name', 'ddl_title' => 'title', 'ddl_address' => 'address', 'new_col' => 'New Col'));

$crud->callbackColumn('new_col', function($value, $row){
    return 'some text';
});

Inside the td for this cell I receive this:

<td class="gc-data-container"><span>&nbsp;</span></td>

I'm using version 2.7.2 with Laravel 5.5

 

Please guide to the correct way to use it in Enterprise, I have been using GroceyCRUD Community for many years but is my first attempt with Enterprise.

 


w.jonker
  • profile picture
  • Member

Posted 14 March 2019 - 12:37 PM

He Blexis,

 

I'am on Grocery Crud version 2.7.1, the following code works without any problems. 

 

$crud->callbackColumn('aantal_woensdag', function ($value, $row) {
return number_format($value, 2, '.', '');
});

w.jonker
  • profile picture
  • Member

Posted 14 March 2019 - 14:18 PM

I updated today to 2.7.2 and the problem is not existing by me.

 

You might try to remove all stuff that is not needed (like the columns and displayAs stuff). And the only add callbackColumn to see if this works. If this is working you can add extra functionality one by one. Are you able to post the code for the complete controller, not only the snippet you show.


blexis
  • profile picture
  • Member

Posted 14 March 2019 - 22:17 PM

Hi w.jonker,

 

thank you for your help. I tried removing all non-necessary code but the problem persists.

 

I saw another thing that the return from the ajax call to retrieve the info or "datagrid" state/action, the call is not returning my callbackColumn, an example:

{
  "filtered_total": 105,
  "data": [
    {
      "ddl_id": "81",
      "ddl_name": "Dance 2019",
      "grocery_crud_extras": {
        "primaryKeyValue": "81"
      }
    },
    ...
  ]
}

To get this, I only use this code:

$crud = new Crud();
$crud->setTable('ddl_deadline');
$crud->columns(['ddl_name', 'new_col']);
$crud->callbackColumn('new_col', function($value, $row){
    return 'some text';
});

I'm thinking that because my new_col is not defined in my table I not getting their data back but I remember that wasn't a requirement to have it in your table and only need to be defined in columns(). I see my new_col in the datagrid but empty.

 


blexis
  • profile picture
  • Member

Posted 14 March 2019 - 22:29 PM

I tried another thing when I use callbackColumn with a table column it worked.

$crud = new Crud();
$crud->setTable('ddl_deadline');
$crud->columns(['ddl_name', 'new_col']);
$crud->callbackColumn('new_col', function($value, $row){
    return 'some text';
});
$crud->callbackColumn('ddl_name', function($value, $row){
    return 'some text';
});

I used this code and for the column that exists in the database table callbackColumn worked but with the column that not exits in the database table didn't work. 


w.jonker
  • profile picture
  • Member

Posted 15 March 2019 - 07:29 AM

Ah, i suspect the column needs to exist, otherwise you cannot do a callback on it. Are you able to create a dummy column with the name new_col? This would make it work and solve your problem.