Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
If no values in igx-grid column, how to hide that at the time of grid load?
posted

Could someone please share code snippet to achieve a functionality that if there are no values in igx-grid column, hide that at the time of load.

Parents
  • 1560
    Offline posted

    Hello,


    I have been looking into your question and prepared a small sample in order to demonstrate how such behavior could be achieved.
    An approach I could suggest is to handle the grid's onColumnInit event. It would be fired for each column after the onInit and as an event argument is passed the initialized column, so you would have access to all of its properties.


    In the event handler, you could check whether the data has values in this column and besed on this to set the column hidden property to true or false. For the purposes of the example, I'm logging the hidden column names in the cosole:

    public onColumnInit(event: IgxColumnComponent) {
        const field = event.field;
        let isHidden = true;
        this.data.forEach(item => {
          if (item[field] !== null) {
            isHidden = false;
            return;
          }
        });
        if (isHidden) {
          console.log(event.field);
        }
        event.hidden = isHidden;
      }


    Here could be found my sample for your reference. Please test it on your side and let me know if I may be of any further assistance.


    Sincerely,
    Teodosia Hristodorova
    Associate Software Developer

Reply Children