How to condtionally set the itemsSource property of combo-box by selected item

Posted by: mayank.topiwala on 16 July 2019, 11:34 am EST

    • Post Options:
    • Link

    Posted 16 July 2019, 11:34 am EST

    Hi Team,

    We are using licensed version of wijmo flex grid for our application and we are having this requirement. So by using this link: https://www.grapecity.com/forums/wijmo/how-to-add-wijmo-combo-box: I can’t achieve the full solution because I am binding the data dynamically in my FlexGrid and user has the choice to add as many as number of rows by double click on the cell. (so I have to use cellType as ‘CellEdit’ in this case). So when the user first double-click inside a cell to put it in edit mode, I can’t find id to other combo-box and hence it unable to set the itemsSource property of this control. I am posting my code here please let me know if you have any solution for this. Thanks in advance.

    <wj-flex-grid #flex [itemsSource]="data" [allowAddNew]="true" [allowDelete]="true"
          (keydown)="onFlexKeydown(flex,$event)">
          <wj-flex-grid-filter #filter></wj-flex-grid-filter>
          <wj-flex-grid-column [binding]="'exposureType'" [header]="'Exposure Type'" [width]="'*'">
            <ng-template wjFlexGridCellTemplate [cellType]="'Cell'" let-cell="cell" let-item="item">
              <wj-combo-box id="exposureTypeCombo{{cell.row.index}}" [itemsSource]="exposures"
                [displayMemberPath]="'exposureType'" [(selectedValue)]="cell.item.exposureType"
                [selectedValuePath]="'exposureType'" [(text)]="cell.item.exposureType" [isRequired]="false"
                [isEditable]="false" (selectedIndexChanged)="onSelectedIndexChanged(cell, cell.item.exposureType)">
              </wj-combo-box>
            </ng-template>
          </wj-flex-grid-column>
          <wj-flex-grid-column [binding]="'exposureName'" [header]="'Exposure Name'" [width]="'*'">
            <ng-template wjFlexGridCellTemplate [cellType]="'Cell'" let-cell="cell" let-item="item">
              <wj-combo-box id="exposureNameCombo{{cell.row.index}}" [itemsSource]="exposureNames"
                [displayMemberPath]="'exposureName'" [(selectedValue)]="cell.item.exposureNameID"
                [selectedValuePath]="'exposureNameID'" [(text)]="cell.item.exposureName" [isRequired]="false"
                [isEditable]="false" (selectedIndexChanged)="onSelectedIndexChanged(cell, cell.item.exposureName)">
              </wj-combo-box>
            </ng-template>
          </wj-flex-grid-column>
          <wj-flex-grid-column [header]="'Exposure Value'" [binding]="'exposureValue'" [width]="'*'"></wj-flex-grid-column>
                    </wj-combo-box>
            </ng-template>
    
        </wj-flex-grid>
    
  • Posted 17 July 2019, 5:51 am EST

    Hi Mayank,

    You may use the NewCellTemplate cell type in WjFlexGridCellTemplate so that the combo box becomes available as soon as the user starts editing the new row. Please refer to the sample attached.

    You may also achieve the behavior by using dynamic data maps. You may handle the beginningEdit event of the FlexGrid and set the dataMap of the exposureName column using the value of the exposureType column. Please refer to the sample attached.

    FlexGrid.zip

    Regards,

    Ashwin

  • Posted 17 July 2019, 8:49 am EST

    Excellent Ashwin. DataMap works like a charm. I can achieve conditional binding using this approach. But there is one small issue. After selecting exposure type: I am able to bind its corresponding exposure names in the dropdown but once I select exposure name I am in need to pass exposure name id to the backend (display member should be exposure name). I was able to achieve this functionality using [(text)] property of wj-combo-box which display the exposure name and using [(selectedValue)] I was able to set exposureNameID of selected item. Can you please advise how we can achieve this functionality using dataMap ?

  • Posted 17 July 2019, 12:55 pm EST

    Hi- Any update on this issue ?



    Thanks,

    Mayank

  • Posted 18 July 2019, 7:52 am EST

    Hi Mayank,

    Yes, you can easily do that by using the key and value properties of DataMap. The value property is used for displaying the values and the key property is used for storing the values.

    In your case, the key would be exposureNameID and value would be exposureName.

    Please refer to the sample below:

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

  • Posted 19 July 2019, 9:16 am EST - Updated 3 October 2022, 7:49 pm EST

    Thanks Ashwin, but I am getting data in a single source which contains both exposureType and exposureNames (data has been group by exposureType). But with your given example you are binding childDataMap from comboChildData which doesn’t happen in my case. I can able to bind my dataMap only from beginEdit function (by setting col.dataMap property). But it doesn’t work consistent. When I mvoed to other row instead of displaying exposureName in the cell it is displaying exposureNameID.

    Below is the sample data source.

    {
        "exposureType": "Spares",
        "exposureNames": [
            {
                "exposureNameID": 22,
                "exposureName": "Aircraft"
            },
            {
                "exposureNameID": 23,
                "exposureName": "ASM"
            }
            {
                "exposureNameID": 24,
                "exposureName": "Spares Value at Risk"
            }
        ]
    }
    

    Attached the screenshot of the issue for your reference.

  • Posted 19 July 2019, 9:17 am EST - Updated 3 October 2022, 7:49 pm EST

  • Posted 21 July 2019, 6:20 am EST

    Hi- Any update on this issue?



    Many Thanks,

    Mayank

  • Posted 22 July 2019, 3:42 am EST

    Hi Team- any update on this issue ?

  • Posted 22 July 2019, 4:13 am EST

    Hi Mayank,

    We are still working on the issue. We will give you an update as soon as possible.

  • Posted 22 July 2019, 6:57 am EST

    Hi Mayank,

    Sorry for the delayed response.

    We are sorry but the desired behavior cannot be achieved using DataMap but instead, you could custom grid editor. To use a custom grid editor, you will need to set the binding of the child column to ‘exposureNames.exposureNameID’. Due to this, the row’s data will now hold a hierarchical object which will be updated by the custom grid editor. Also, we can use the itemFormatter to convert the exposureNameID to exposureName.

    Please refer to the sample below:

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

    Regards,

    Ashwin

  • Posted 22 July 2019, 12:35 pm EST

    Hi Ashwin,

    This approach looks little verbose. So I have manipulated the data coming from backend bind it to the dataMap as per your previous response. I am going to mark that approach as my answer. Thanks a lot for your help.



    Best Regards,

    Mayank

  • Posted 22 July 2019, 11:57 pm EST

    Hi Mayank,

    We are glad that we were able to solve your issue. Please let us know if you have any further queries.

    Regards,

    Ashwin

  • Posted 25 July 2019, 12:49 pm EST - Updated 3 October 2022, 3:12 pm EST

    Thanks Ashwin, I have posted another question on the forum. Please take a look if you can get a chance. https://www.grapecity.com/forums/wijmo/wj-input-date-gets-disappe

  • Posted 26 July 2019, 12:29 am EST

    Hi Mayank,

    I have replied to your forum post below:

    https://www.grapecity.com/forums/wijmo/wj-input-date-gets-disappe

Need extra support?

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

Learn More

Forum Channels