akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 877 forks source link

Hidden column #95

Open radni1234 opened 7 years ago

radni1234 commented 7 years ago

Is it possible to add hidden column or hide existing column in table?

PrazSam commented 7 years ago

Is this still impossible? Is there any workaround?

nnixaa commented 7 years ago

Hi @PrazSam, unfortunately, we don't have this feature out of the box, could you describe your use case though?

PrazSam commented 7 years ago

Thanks for the quick reply. My table already has lots of columns. Therefore I must reduce columns as much as possible for the ease of view. At least I want to hide the id column from user which contains the unique id for update delete purposes.

Frisky- commented 7 years ago

I got the same problem, did you find workaround ?

PrazSam commented 7 years ago

I'm afraid not. There must be a workaround since it's mentioned that the feature is not a out of the box one. I tried to hide them using css with classes (with column names), but my poor css didn't help or the way they have written, makes it difficult.

lynings commented 7 years ago

I also encountered this problem, but I am by modifying the source to solve this problem. This is my configuration, the interface will not show id image Step:

  1. To /node_modules/ng2-smart-table/lib/data-set/column.js add show field image image
  2. add [ngStyle]=\"{'display': cell.column.show ? '': 'none'}\" and [ngStyle]=\"{'display': column.show ? '': 'none'}\" to template or hidden]=\"!column.show\" and hidden]=\"!cell.column.show\" To /node_modules/ng2-smart-table/components/thead/rows/thead-titles-row.component.js image To /node_modules/ng2-smart-table/components/thead/rows/thead-filters-row.component.js image To /node_modules/ng2-smart-table/components/tbody/tbody.component.js image To /node_modules/ng2-smart-table/components/thead/rows/thead-form-row.component.js image

This is OK.

allanffg commented 7 years ago

@lynings Do you want to create a pull request for this change? Would be good to have in the main build.

kane-armstrong commented 7 years ago

I ran into this problem too, thinking that I'd need a property in the columns section of settings before I could see it in any of the raised events.

Logging the event data to console reveals this not to be the case - all of the fields in your component are in there, regardless of whether or not you show them in the grid.

With that in mind, I don't see how a "show" flag is necessary - just delete the column, you still have access to the property when handling events.

ouchl commented 7 years ago

I am facing the same issue. Here is my workaround. I have id column in data source but not in the settings->columns. When create add id property to event.newData then resolve it. Here is my code for a interview project. onCreateConfirm(event): void { this.service.addInterviewer(event.newData) .then(data => event.newData.interviewer_id = data) .then(data => event.confirm.resolve(event.newData)); } onEditConfirm(event): void { this.service.saveInterviewer(event.data.interviewer_id,event.newData) .then(data => event.confirm.resolve(event.newData)); } addInterviewer(data): Promise { return this.http.post(this.interviewerUrl,data) .toPromise() .then(response => response.json()) .catch(this.handleError); }

saveInterviewer(id,data): Promise { return this.http.put(${this.interviewerUrl}/${id},data) .toPromise() .then(response => response.json()) .catch(this.handleError); }

phillaurin commented 7 years ago

@ouchl Thanks for the idea, I've been jungling with the same problem and it worked for me as well. Real easy to implement !

ronit123321 commented 7 years ago

@lynings i did try the hack and it did work, but when i update the columns show attribute on toggle() the table data does not update. Could you point what i may have missed.

goodwinmcd commented 7 years ago

I don't think his hack was meant to toggle the columns, only to hide it when it is first loaded. If you toggle the show attribute to hide/show the column then you will need to update the table settings afterwards.

hoodslide commented 7 years ago

Here's a straightforward way to toggle columns. Comments welcome! In your Grid component class:

export enum ShowColumns { All, Some }

@Component({
  ...
})
@Injectable()
export class GridComponent {
  ShowColumns = ShowColumns;   // exposes enum to template
  settings = this.getSettings();

  private getSettings() {
    return ({
      columns: this.getColumns(this.showColumns),
      actions: { add: false, edit: false, delete: false },
      pager: { display: true, perPage: 10 },
    });
  }

  private setColumns(showColumns: ShowColumns) {
    this.settings = Object.assign({}, this.getColumns(showColumns));
  }

  private getColumns(showColumns: ShowColumns) {
    let columns = {
        status: {
          title: 'Status',
          filter: false,
          editable: false,
          type: 'custom',
          renderComponent: StatusCellComponent,
        },
        customer: {
          title: 'Customer',
          filter: false,
          editable: false,
        },
    };
    if (showColumns == ShowColumns.All) {
      columns['one_more'] = {
        title: 'Uno Mas',
        filter: false,
        editable: false,
        sort: false,
        type: 'custom',
        width: '66px',
        renderComponent: SomeCellComponent,
      };
    }
    return columns;
  }
lucasalvarezlacasa commented 6 years ago

There's no out of the box solution for this yet? I'm facing the same problem, I don't want the end user to see the ID column for safety reasons.

Any suggestions?

lucasalvarezlacasa commented 6 years ago

+1 to @kane-armstrong, if you don't want to display a field on the table, just ignore it on the settings and you will be good to go. Later on, when you receive the event information (for add, edit and delete), everything that you originally set in the source will be there :).

ame589 commented 6 years ago

Any solutions?

StevePires commented 6 years ago

Can't believe this hasn't been added yet... the solution is so straight forward... There has been a PR for 2 months and it has been pending since because of Travis CI...

Huyliver6793 commented 6 years ago

I got the same problem, my solution is fix code in file node_module but i don't want fix it because every time, i run npm install, it will reset. Is there any solution?

sugiserv commented 6 years ago

@Huyliver6793 you could fork the repository, modify the code and use your own repository in your project.

AndyCyberSec commented 6 years ago

Actually it's very simple: You make a table data model with all the data you need. Then in columns settings simply do not wite or just comment the columns you do not want to show. So when selecting, deleting or updating rows you will still have id field property (for example) although it is not shown in table columns

ame589 commented 6 years ago

i want to hide and show dinamically!

2018-07-09 11:24 GMT+02:00 Andrea Bruschi notifications@github.com:

Actually it's very simple: You make a table data model with all the data you need. Then in columns settings simply do not wite or just comment the columns you do not want to show. So when selecting, deleting or updating rows you will still have id field (for example) although it is not shown in table columns

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/akveo/ng2-smart-table/issues/95#issuecomment-403416648, or mute the thread https://github.com/notifications/unsubscribe-auth/AGWO2UR6mqTJOX7q7guugUb-sHzJVMi6ks5uEyEygaJpZM4K_YJs .

-- Amedeo Tortora

phone: +39 3480124800 skype: amedeo.tortora

nwzhaider commented 6 years ago

Add class: 'd-none' in settings to hide the column as below...

settings = { columns: { column: { title: 'col', class: 'd-none'

  },....
lenichols commented 6 years ago

Why isnt this a part of the build? toggling colums seems to be a hott topic in the issue thread... can anyone construct notes on how to show/hide?

avdbrink commented 5 years ago

I needed this as well. I've build the same solution as @lynings and pushed it to npm @avdbrink/ng2-smart-table. Here's my PR

suyogbaldota-zibtek commented 4 years ago

Do we have any solution for hiding a column in ng2-smart-table (of version 1.5.0) for Angular 8?

I also encountered this problem, but I am by modifying the source to solve this problem. This is my configuration, the interface will not show id image Step:

  1. To /node_modules/ng2-smart-table/lib/data-set/column.js add show field image image
  2. add [ngStyle]=\"{'display': cell.column.show ? '': 'none'}\" and [ngStyle]=\"{'display': column.show ? '': 'none'}\" to template or hidden]=\"!column.show\" and hidden]=\"!cell.column.show\" To /node_modules/ng2-smart-table/components/thead/rows/thead-titles-row.component.js image To /node_modules/ng2-smart-table/components/thead/rows/thead-filters-row.component.js image To /node_modules/ng2-smart-table/components/tbody/tbody.component.js image To /node_modules/ng2-smart-table/components/thead/rows/thead-form-row.component.js image

This is OK.

sivaprasadbkamath commented 4 years ago

Is it a part now atleast???

angelo24983 commented 4 years ago

@lynings Do you want to create a pull request for this change? Would be good to have in the main build.

manar-mk commented 4 years ago

Hi guys, any updates on this issue?

vamidi commented 4 years ago

Think this issue can be closed because of pull https://github.com/akveo/ng2-smart-table/pull/1151