Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork69
Add parameter in addCheckbox to prepend or append the checkbox column#55
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Add parameter in addCheckbox to prepend or append the checkbox column.
karmendra commentedFeb 5, 2018
Can someone review this please, CI has failed, its suggestions are not what we would expect in the code. Can someone confirm if we are waiting for CI to Pass before this PR is visible for review? |
Namoshek commentedFeb 26, 2018
Just had a look at your PR and to me it looks fine (technically and style). I can confirm that the suggested StyleCI changes are not related to the changes of yours. I just have one suggestion for an improvement: Maybe make the new parameter $this->builder() ->columns([ ['data' =>'id','title' =>'ID'], ['data' =>'name','title' =>'Name'], ['data' =>'email','title' =>'Email'], ['data' =>'telephone','title' =>'Telephone'], ]) ->addCheckbox(['data' =>'is_admin','title' =>'Admin?'],2); which would hopefully give you something like where Obviously this would require some edge case handling to cover when there is a too high index for example. |
yajra commentedFeb 27, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry for overlooking this, a bit busy on mobile dev and cannot find time yet for open source projects. Anyways, Update -- |
src/Html/Builder.php Outdated
| ],$attributes); | ||
| $this->collection->push(newColumn($attributes)); | ||
| if($prependColumn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please add a space afterif ($prependColumn)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Added a space after if
karmendra commentedFeb 28, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@Namoshek Very good suggestion, but I am not sure how I can insert an item in Collection at specific index. My quick search showed that we can use splice prepend/push and union functions to do so, but felt that's really not good way to do it. Any other suggestion do let me know. |
Added a missing space after if statement
Namoshek commentedFeb 28, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, I think something along these lines could be a potential solution (completely untested though): /** * Add a checkbox column. Prepends the column at the beginning, * appends it at the end or inserts it at a specified index. * * @param array $attributes * @param bool|int $position true to prepend, false to append or a zero-based index for positioning * @return $this */publicfunctionaddCheckbox(array$attributes = [],$position =false){$column =newColumn(array_merge(['defaultContent' =>'<input type="checkbox"' .$this->html->attributes($attributes) .'/>','title' =>$this->form->checkbox('','',false, ['id' =>'dataTablesCheckbox']),'data' =>'checkbox','name' =>'checkbox','orderable' =>false,'searchable' =>false,'exportable' =>false,'printable' =>true,'width' =>'10px', ],$attributes));if ($position ===true) {$this->collection->prepend($column); }elseif ($position ===false ||$position >=$this->collection->count()) {$this->collection->push($column); }else {$this->collection->splice($position,0, [$column]); }return$this;} If you are curious what the equivalent of the if (is_int($position)) {if ($position >=$this->collection->count()) {$this->collection->push($column); }else {$this->collection->splice($position,0, [$column]); }}else {if ($position) {$this->collection->prepend($column); }else {$this->collection->push($column); }} But I find the above version more readeable and also a bit more logic when thinking about it twice. It makes use of implicit type checks though ( |
Adding checkbox by column position ( zero indexed i.e. index starting from 0)
karmendra commentedMar 4, 2018
@yajra why should the PR target be 3.0 and not master? I am not able to install the changes in Laravel 5.5 and above. I get following error any suggestions? |
Added missing $column variable
karmendra commentedMar 4, 2018
Namoshek left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for adding the changes! Here just two minor style hints:
src/Html/Builder.php Outdated
| ],$attributes); | ||
| $this->collection->push(newColumn($attributes)); | ||
| $column =newColumn($attributes); | ||
| if ($position ===true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think you mixed up the indent from line 423 to 429 a little bit, there is a tabstop involved and the indent is off by 1.
| 'width' =>'10px', | ||
| ],$attributes); | ||
| $this->collection->push(newColumn($attributes)); | ||
| $column =newColumn($attributes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe add an empty line after$column = new Column($attributes);, StyleCI most likely doesn't like it like this. 👍
Fixed Indentation and line breaks
karmendra commentedMar 15, 2018
@yajra can you please check why it is still showing "1 review requesting changes" for one of your review. I already made the required changes. |
yajra commentedMar 16, 2018
Sorry for the delays, released on v3.7.1 thanks! |
Add parameter in addCheckbox to prepend or append the checkbox column.
When I try to add a checkbox column as the first column as following it doesn't show the checkbox column at all, if I put the
addCheckbox()aftercolumnsit comes as the last column.