⚠ 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

Unable to get value by callback_column



Jubayer Arefin

Jubayer Arefin
  • profile picture
  • Member

Posted 03 July 2012 - 11:14 AM

Hello guys I needed to use the "callback_column" but it is not working as I expected.


$this->grocery_crud->callback_column('username', function($value, $row) {
return uc_first($value);
});


This is my code and it is supposed to return the usernames with uppercase for every row. Do I have to do anything else.

And I have also used the other format for php 5.2 but no use.

Plz correct me if I am wrong.

Thanks in advance.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 03 July 2012 - 20:33 PM

This bug takes me lot of time to find it, the problem is the actually fix with the set_relation. Don't worry about those kind of problems as I am preparing a big release as for the next version and I will probably rewrite the set_relation queries as I have some small problems with the callback_column callbacks and set_relation.

Ok back to your problem now. The problem is that you probably have some conflict with the field name and the set_relation . For example if you have the 'username' at your basic table and you have a set_relation like this:


$this->grocery_crud->set_relation('user','cms_users','username'); //same field name


With the last bug fix you will have a problem using the callback as you have to do it like this (let's say that your primary table is "users"):


$this->grocery_crud->callback_column('users.username', function($value, $row) {
return uc_first($value);
});


and it will work.

Jubayer Arefin

Jubayer Arefin
  • profile picture
  • Member

Posted 04 July 2012 - 01:29 AM

It did not work. This is my code. Am I setting the relation properly ? I am sending the tables by pm.


$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->set_table('balances');
//Validation
$this->grocery_crud->required_fields('amount');
$this->grocery_crud->required_fields('user_id');
//Set relation
$this->grocery_crud->display_as('user_id', 'User Name');
$this->grocery_crud->set_subject('Balance');
$this->grocery_crud->set_relation('user_id', 'users', 'username');
//Set relation
//Change default
$this->grocery_crud->callback_column('users.username', function($value, $row) {
return uc_first($value);
});

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 July 2012 - 06:16 AM

In your case you have to use this work-around :

http://www.grocerycr...p__982#entry982

So in your case will be:

$crud->callback_column($this->unique_field_name('user_id'),function($value, $row) {
return uc_first($value);
});


I haven't checked it but it should work

Jubayer Arefin

Jubayer Arefin
  • profile picture
  • Member

Posted 04 July 2012 - 07:47 AM

It gives me this error.


Fatal error: Call to undefined method Balance::unique_field_name() in F:\xampp\htdocs\surveybangladesh\application\controllers\balance.php on line 43

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 July 2012 - 08:43 AM

Add this to your controller

function unique_field_name($field_name) {
return 's'.substr(md5($field_name),0,8);
}

Jubayer Arefin

Jubayer Arefin
  • profile picture
  • Member

Posted 04 July 2012 - 08:57 AM

Thanks a lot mate. It worked :)

alchifer

alchifer
  • profile picture
  • Member

Posted 11 January 2017 - 09:32 AM

I work in list form, but in edit form it doesn´work.

Any solution?

 

Thanks


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 18 January 2017 - 02:30 AM

well my friend - column callback is ment to be a callback for formatting the colum in the listing..

for edit - u need to do a callback_field ... to get it going... Refer to the document - u will surely get solution there for the same.