Jump to content


callbackColumn not working

callbackColumn

  • Please log in to reply
5 replies to this topic

#1 blexis

blexis

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 12 March 2019 - 09: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.

 



#2 w.jonker

w.jonker

    Member

  • Members
  • PipPip
  • 13 posts

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, '.', '');
});


#3 w.jonker

w.jonker

    Member

  • Members
  • PipPip
  • 13 posts

Posted 14 March 2019 - 02: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.



#4 blexis

blexis

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 14 March 2019 - 10: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.

 



#5 blexis

blexis

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 14 March 2019 - 10: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. 



#6 w.jonker

w.jonker

    Member

  • Members
  • PipPip
  • 13 posts

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.







Also tagged with one or more of these keywords: callbackColumn

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users