Jump to content


Unable to get value by callback_column

callback_column callback column

  • Please log in to reply
8 replies to this topic

#1 Jubayer Arefin

Jubayer Arefin

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationDhaka, Bangladesh

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.

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,095 posts
  • LocationLondon

Posted 03 July 2012 - 08: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.
Posted Image

#3 Jubayer Arefin

Jubayer Arefin

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationDhaka, Bangladesh

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);
				    });


#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,095 posts
  • LocationLondon

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
Posted Image

#5 Jubayer Arefin

Jubayer Arefin

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationDhaka, Bangladesh

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


#6 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,095 posts
  • LocationLondon

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);
		}

Posted Image

#7 Jubayer Arefin

Jubayer Arefin

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationDhaka, Bangladesh

Posted 04 July 2012 - 08:57 AM

Thanks a lot mate. It worked :)

#8 alchifer

alchifer

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 11 January 2017 - 09:32 AM

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

Any solution?

 

Thanks



#9 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users