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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column Moving using API #6334

Closed
amitohale opened this issue Dec 11, 2019 · 5 comments · Fixed by #8012
Closed

Column Moving using API #6334

amitohale opened this issue Dec 11, 2019 · 5 comments · Fixed by #8012
Assignees
Labels
grid: column-moving 🧰 feature-request ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.

Comments

@amitohale
Copy link

Ability to reorder columns using API

Current grid allow columns reordering via standard drag/drop mouse or touch gestures. It does not allow us to reorder based on saved preferences (somewhere.. say localstorage).

Support must be added to set column position in a grid.

  1. setColumnIndex(column: IgxColumnComponent, index: number): Set column position to index
@zdrawku
Copy link
Contributor

zdrawku commented Jan 2, 2020

Hey @amitohale, thank you for the feature suggestion, while we review the Feature Request and plan it for the upcoming sprints you may use this temporary solution.

The sample demonstrates how to change the columns order based on column field name by using a ComponentFactoryResolver, which will help us to create new column instances and add them to the cleared columnListlist.

Code snippet:

changeColumnsOrder(): void {
      const newColumns = [];
      let newColumnsOrder = [];
      this.grid.columnList.forEach(col => newColumnsOrder.push(col.field));
      const factory = this.resolver.resolveComponentFactory(IgxColumnComponent);
      newColumnsOrder = this.asc ? newColumnsOrder.sort().reverse() : newColumnsOrder.sort();

      newColumnsOrder.forEach(colField => {
          const ref = factory.create(this.viewRef.injector);
          const col = this.grid.columnList.find(c => c.field === colField);
          Object.assign(ref.instance, col);
          ref.changeDetectorRef.detectChanges();
          newColumns.push(ref.instance);
      });

      this.grid.columnList.reset(newColumns);
      this.grid.columnList.notifyOnChanges();
    }

Order

@amitohale
Copy link
Author

Thanks @zdrawku, this works for me.

@zdrawku
Copy link
Contributor

zdrawku commented Jan 3, 2020

The feature-request is added to our Queue part of the Master Backlog, you will be updated accordingly for any change of its state.

@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label May 11, 2020
@zdrawku zdrawku reopened this May 20, 2020
@zdrawku zdrawku removed the status: inactive Used to stale issues and pull requests label May 20, 2020
@zdrawku
Copy link
Contributor

zdrawku commented Jun 17, 2020

As @hanastasov pointed out while we were discussing the FR, we can expose API method (column-based) that will change the column index and reset the columnist collection (similar to the moveColumn API implementation).

list.splice(toIndex, 0, ...list.splice(fromIndex, 1));
this.columnList.reset(list);

I am marking this FR for the next milestone

@hanastasov hanastasov added ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged. and removed 🛠️ status: in-development Issues and PRs with active development on them labels Aug 27, 2020
@hanastasov hanastasov mentioned this issue Aug 27, 2020
14 tasks
hanastasov added a commit that referenced this issue Aug 27, 2020
hanastasov added a commit that referenced this issue Aug 27, 2020
hanastasov added a commit that referenced this issue Aug 27, 2020
hanastasov added a commit that referenced this issue Aug 27, 2020
hanastasov added a commit that referenced this issue Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grid: column-moving 🧰 feature-request ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants