How to bind imported data from excel grid when user comes back from next page

Posted by: mayank.topiwala on 28 August 2019, 7:11 am EST

  • Posted 28 August 2019, 7:11 am EST - Updated 3 October 2022, 7:28 pm EST

    Hi,

    We have Angular 7 wizard application in which user can able to bind the data from excel sheet into wijmo flex grid. I can able to successfully import the data, bind it inside the model and then save it into the database when user clicks on NEXT button. The problem is when user comes back to previous page it binds data twice with the selected value property and not the display property. Can you please let me know how to bind the data again into grid ?

    Below is the code for import functionality(the code is large so I put the main approach here) :

    bindImportedDataIntoModel() {
        const newData = _.cloneDeep(getImportedCVData(this.flex));
    
        let columns = JSON.parse(this.flex.columnLayout).columns;
        this.data = new wjcCore.CollectionView(newData);
        this.flex.autoGenerateColumns = true;
        this.flex.itemsSource = this.data;
        this.flex.collectionView.refresh();
    
        const newCol = JSON.parse(this.flex.columnLayout).columns;
        newCol.splice(0, columns.length);
        columns = { columns: newCol };
        this.flex.columnLayout = JSON.stringify(columns);
    
        this.bindPolicyLimtitID();
        this.bindCoverageID();
        this.deepGridCopy();
        this.trackGridDataChanges();
      }
    

    Below is the code to bind data into grid:

     ngOnInit() {
        this.publishDataService.currentData$.subscribe(data => {
          if (data && data.gridType && data.gridType === GridType.POLICY_DETAILS_GRID) {
            const gridData: wjcCore.CollectionView = _.cloneDeep(data.gridData);
            this.data = new wjcCore.CollectionView(gridData);
    
            if (data.coverages) {
              this.coverages = new wjcGrid.DataMap(data.coverages, 'coverageID', 'coverage');
            }
            if (data.limitNames) {
              this.limitNames = new wjcGrid.DataMap(data.limitNames, 'limitNameID', 'limitName');
            }
    
            this.trackGridDataChanges();
            this.deepGridCopy();
          }
        });
    
        this.showToolTip();
      }
    

  • Posted 28 August 2019, 9:56 am EST

    Hi Team, any update on this?

  • Posted 29 August 2019, 4:10 am EST

    Hi Mayank,

    We are sorry but we were not able to replicate the issue. Could you please take a look at the sample below and let us know if we are missing something or you may modify the sample so that replicates the issue.

    https://stackblitz.com/edit/angular-ndupbg

    Regards,

    Ashwin

  • Posted 29 August 2019, 6:49 am EST - Updated 3 October 2022, 3:01 pm EST

    Hi Ashwin,

    Below is the same code to bind the import excel but it doesn’t gets bind when user comes back from previous page:

    onImportExcel(event) {
        const fileInput = event.importFile['nativeElement'];
        const self = this;
        if (fileInput.files[0]) {
          const reader = new FileReader();
          reader.onload = function () {
            const workbook = new wjcXlsx.Workbook();
            workbook.load(<string>reader.result);
            if (isValidExcel(self.flex.columns, workbook)) {
              wjcGridXlsx.FlexGridXlsxConverter.load(self.flex, reader.result, {
                includeColumnHeaders: event.includeColumnHeader,
                includeCellStyles: false
              });
              self.flex.columns.forEach(col => {
                col.width = '*';
              });
              self.constructNotionalSplitsModel();
            } else {
              event.errPopup.show(true);
            }
          };
          reader.readAsDataURL(fileInput.files[0]);
        }
      }
    
    constructNotionalSplitsModel() {
        if (this.flex && this.flex.rows && this.flex.rows.length > 0) {
          this.model[0] = [];
          for (let row = 0; row < this.flex.rows.length; row++) {
            const item = {};
            for (let col = 0; col < this.flex.columns.length; col++) {
              const cellValue = this.flex.getCellData(row, col, false);
              switch (this.flex.columns[col].header) {
                case 'Notional Split Type':
                  item['notionalSplitType'] = cellValue;
                  break;
                case 'Notional Split Value':
                  item['notionalSplitValue'] = cellValue;
                  break;
                case 'Liabilities Rating Criteria':
                  item['liabilitiesRatingCriteria'] = cellValue;
                  break;
    
                default:
                  break;
              }
            }
            this.model[0].push(item);
          }
          this.getObjectIDsByNames();
        }
      }
    

    Then below code gets called when user comes back again this page and grid becomes empty:

    ngOnInit() {
        this.publishDataService.currentData$.subscribe(data => {
          if (data && data.gridType && data.gridType === GridType.NOTIONAL_SPLITS_GRID) {
            const gridData: wjcCore.CollectionView = _.cloneDeep(data.gridData);
            this.data = new wjcCore.CollectionView(gridData);
    
            this.trackGridDataChanges();
            this.deepGridCopy();
          }
        });
    
        this.showToolTip();
      }
    
  • Posted 29 August 2019, 8:36 am EST

    Hi Ashwin,

    I have found the root cause. Basically when I import the data in Flexgrid then it loses all the binding made to the FlexGrid columns. So the grid now have the different column layout. Is there any way we can apply the ‘binding’ property again. I have attached two column layouts of a grid. One before imports the data and one after it. Please check and let me know how we can achieve this functionality ?

    Thanks,

    Mayank

  • Posted 29 August 2019, 8:37 am EST

    PFA json files

  • Posted 29 August 2019, 8:39 am EST

  • Posted 29 August 2019, 1:10 pm EST

    Hi team, any update on this ?

  • Posted 30 August 2019, 6:50 am EST

    Hi Mayank,

    We are working on this case. We will give you an update as soon as we have further information.

  • Posted 2 September 2019, 2:35 am EST

    Hi Mayank,

    From what I understand, you have already created columns in the FlexGrid before importing the excel file. And when the excel file is imported, the column layout of the FlexGrid changes and the binding property gets removed.

    If this is your issue, then you may avoid this by saving the columnLayout property of the FlexGrid before importing the excel file and then assigning it again to the grid after importing the excel file.

    Please refer to the sample below:

    https://stackblitz.com/edit/angular-5dnfnw

    Also, please use the excel file attached below for running the sample.

    grid.zip

    Let me know if this was your requirement or otherwise.

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels