Skip to content

Conversation

@jnbn
Copy link

@jnbn jnbn commented Jan 30, 2016

for specifying different colum names. (table headers)

When you're using with pre defined arrays from controllers, they usually include database colum names which needs to be displayed properly and this method overrides the titles.

Let's say you have id,name,is_approved and timestamps on your companies object which you get from your ORM and converted to an array as expected to work with Tables.

like

$companies= Company::all(['id','name','is_approved','created_at','updated_at'])->toArray();

Normally it should display those keys but now you can use it like to override certain fields.

Table::withContents($companies)->withHeaderCaptions([
                        'is_approved' => 'Approval Status',
                        'created_at' => 'Creation Date',
                        'updated_at' => 'Last Update',
                    ])->callback('Actions', function ($field, $row) { 
                    return '<a class="btn btn-default" href="'.route('companies.edit',$row['id']).'">Edit</a>'.' <a class="btn btn-danger" href="'.route('companies.destroy',$row['id']).'">Delete</a>'; 
                });

Other fields like id and name would be displayed as themselves.

for specifying different colum names. (table headers)
@jnbn jnbn closed this Jan 31, 2016
@PatrickRose
Copy link
Collaborator

I see you closed this - for future people that see this implementing the TableInterface is probably a better bet instead of converting your model to an array.

@jnbn
Copy link
Author

jnbn commented Jan 31, 2016

Oh I didn't realize there was an interface sorry.

By the way, I saw that items are rendered according to the $headers in renderItem method so i cancelled the request. Do you have any suggestions for implementation instead of modifying renderItem method?

@PatrickRose
Copy link
Collaborator

I don't think this is a feature that's needed to be honest. If you need to a different caption for a column then you should convert that before you send it to the Table object. In this case since you're already using a model it's much simpler to have your model implement the TableInterface so you get the headers you want.

@PatrickRose
Copy link
Collaborator

Actually - this is just changing the caption for the header right? Then getHeaders() and renderHeaders() are the functions that need to be edited.

@jnbn
Copy link
Author

jnbn commented Jan 31, 2016

Yeah but renderItems uses $value = $this->getValueForItem($item, $heading); and if you change the keys on header you can not display the items on the table properly

@PatrickRose
Copy link
Collaborator

Yes - but all your changing is the header caption. You should just need to edit renderHeaders and possibly getHeaders

@jnbn jnbn reopened this Jan 31, 2016
@jnbn
Copy link
Author

jnbn commented Jan 31, 2016

changed the methodname to withHeaderCaptions and modified renderHeaders

@jnbn jnbn changed the title added optional withHeaders method to Tables added optional withHeaderCaptions method to Tables Jan 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants