Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
yajra merged 6 commits intoyajra:3.0fromkarmendra:addCheckbox
Mar 16, 2018

Conversation

@karmendra
Copy link
Contributor

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 theaddCheckbox() aftercolumns it comes as the last column.

  return $this->builder()              ->addCheckbox()               ->columns($this->getColumns())

Add parameter in addCheckbox to prepend or append the checkbox column.
@karmendra
Copy link
ContributorAuthor

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
Copy link
Contributor

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@param bool|int to also allow for positional inserts. Consider something like this:

$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

 ID | Name | Admin? | Email            | Telephone-----------------------------------------------------  1 | Luke |    Yes | luke@example.com | 1234 567890

where2 is the 0-based index of where the checkbox column should go.

Obviously this would require some edge case handling to cover when there is a too high index for example.

@yajra
Copy link
Owner

yajra commentedFeb 27, 2018
edited
Loading

Sorry for overlooking this, a bit busy on mobile dev and cannot find time yet for open source projects. Anyways,will fix the StyleCI and will try to review this within the week. Thanks!

Update --
StyleCI issue seems like like due to targeted branch is master. Updated the PR to target 3.0.

@yajrayajra changed the base branch frommaster to3.0February 27, 2018 01:27
],$attributes);
$this->collection->push(newColumn($attributes));

if($prependColumn) {
Copy link
Owner

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)

Copy link
ContributorAuthor

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
Copy link
ContributorAuthor

karmendra commentedFeb 28, 2018
edited
Loading

@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
Copy link
Contributor

Namoshek commentedFeb 28, 2018
edited
Loading

Yes,$collection->splice($index, $length, $elementsToInsert) is the way to go, I think. Although you could also build a new collection from ground if that's easier for you (due to the very limited amount of entries for the collection, this would not be a performance issue either).

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 theif-elseif-else part is:

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 (=== vs.is_int()).

Adding checkbox by column position ( zero indexed i.e. index starting from 0)
@karmendra
Copy link
ContributorAuthor

@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

vagrant@homestead:~/Code/traknpay$ composer updateLoading composer repositories with package information                                                 Updating dependencies (including require-dev)         Your requirements could not be resolved to an installable set of packages.  Problem 1    - Can only install one of: laravelcollective/html[5.4.x-dev, v5.6.3].    - Can only install one of: laravelcollective/html[5.6.x-dev, 5.4.x-dev].    - Can only install one of: laravelcollective/html[5.6.x-dev, 5.4.x-dev].    - Can only install one of: laravelcollective/html[v5.6, 5.4.x-dev].    - Can only install one of: laravelcollective/html[v5.6.1, 5.4.x-dev].    - Can only install one of: laravelcollective/html[v5.6.2, 5.4.x-dev].    - Can only install one of: laravelcollective/html[v5.6.3, 5.4.x-dev].    - yajra/laravel-datatables-html dev-addCheckbox requires laravelcollective/html 5.4.* -> satisfiable by laravelcollective/html[5.4.x-dev].    - Installation request for yajra/laravel-datatables-html dev-addCheckbox -> satisfiable by yajra/laravel-datatables-html[dev-addCheckbox].    - Installation request for laravelcollective/html ^5.6 -> satisfiable by laravelcollective/html[5.6.x-dev, v5.6, v5.6.1, v5.6.2, v5.6.3].

any suggestions?

@karmendra
Copy link
ContributorAuthor

@Namoshek I implemented your suggestion and tested it as well. worked like a charm.
@yajra please review and let us know your suggestions if any.

Copy link
Contributor

@NamoshekNamoshek left a comment
edited
Loading

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:

],$attributes);
$this->collection->push(newColumn($attributes));
$column =newColumn($attributes);
if ($position ===true) {
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
ContributorAuthor

@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.

@yajrayajra merged commit2b44654 intoyajra:3.0Mar 16, 2018
@yajra
Copy link
Owner

Sorry for the delays, released on v3.7.1 thanks!

Namoshek reacted with hooray emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@yajrayajrayajra approved these changes

+1 more reviewer

@NamoshekNamoshekNamoshek approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@karmendra@Namoshek@yajra

[8]ページ先頭

©2009-2025 Movatter.jp