Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for row attributes and callable cell attributes. #3

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@craigrodway
Copy link
Contributor

commented Jun 15, 2019

Hi there, thanks for this library! 馃檶

I've been using it for a while in a project I'm working on and have found it really useful, but came up with a requirement to customise the generated <tr> elements (e.g. adding data- and class attributes).

First I tried creating a new class to extend it, but had problems due to the variables being declared private; so I forked it instead - you can see the changes here.

I updated test1.php example with some use cases - setting the 'class' and adding a data-id attribute based on row properties.

The way I achieved this - updating Properties class to support callables - also means that the attr() and css() calls for cells can also have values returned from callables.

Please feel free to merge if you find it useful!

@jupitern

This comment has been minimized.

Copy link
Owner

commented Jun 18, 2019

Hi Craig,
Thanks for the suggestions. Makes perfect sense.
Regarding the implementation I think to add attributes and css to different tags I would rather have something like:

->attr('table', 'width', '100%')
->attr('tr', 'data-text', 'bla bla bla bla bla')
->css('tr', 'background-color', 'red')
->column()
		->title('Name')
		->value(function ($row) {
			return rand(1,10)%2 ? '<b>'.$row['name'].'</b>' : $row['name'];
		})
		->attr('td', 'data-text', 'bla bla bla')
		->css('th', 'color', 'green')
		->css('td', 'width', '50%')
		->css('td', 'background-color', '#ccc', true)
->add()

Example:
https://github.com/jupitern/table/blob/development/src/Examples/test1.php

I used your suggestions and added a development branch with the ideia. I have not implemented the callables feature but take a look and tell me what you think.
https://github.com/jupitern/table/tree/development

@craigrodway craigrodway referenced this pull request Jun 19, 2019

Merged

Updated callable values #4

@craigrodway

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2019

Hi, thanks for your reply!

I agree, I prefer that syntax and makes more sense that way. I think I was being cautious not to break compatibility too much, but this way is good. I've checked it out and like it how it works.

I've made some adjustments to support callable values which you can see in PR #4 .

@jupitern jupitern closed this Jun 19, 2019

@jupitern

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.