Grid and Combobox with different models

Hi Support Team

I tried to combine 2 different models.

This is my code.

Screenshot 2021-08-09 173252-min.png


My first problem is data in GridForeignColumn Field=@nameof(Crypto.Symbol) is always null after adding new rows.

My second problem is Combobox in Add Dialog always keeps the latest value and does not refresh after adding new or editing.

All my code is in the archive file.

I also add 2 gif files to help you know about that cases 

"Gif Problem Files\Data from Droplist couldn't add.gif"

"Gif Problem Files\Add Dialog - Combobox not refesh and still keep current value.gif"

Thanks


Attachment: ProblemDemo_6a6444dd.zip

3 Replies

RN Rahul Narayanasamy Syncfusion Team August 10, 2021 01:06 PM UTC

Hi Khang, 

Greetings from Syncfusion. 

Query: Problem with saving the foreign key column values with edit template 

We have validated your query and checked the reported problem with the provided information(Gif and sample). From your code snippets, you have not defined primary key columns(IsPrimaryKey) in the Grid. We would like to inform you that the Editing feature requires a primary key column for performing CRUD operations. To define the primary key, set IsPrimaryKey to true in particular column whose value is unique


We have defined the primary column as CryptoId column in your sample. You need to provide unique value for that column while adding. 

After that you can resolve the reported problem by defining @bind-Value like below to resolve the problem. Find the below code snippets and sample for your reference. 

 
<div id="iPage"> 
    <SfGrid DataSource="@cryptos" ID="Grid" @ref="Grid" 
            AllowPaging="true" 
            . ..  
        <GridColumns> 
            <GridColumn Field=@nameof(Crypto.CryptoId) HeaderText="Crypto ID" HeaderTextAlign="TextAlign.Center" IsPrimaryKey="true" AllowAdding="false" AllowEditing="false"></GridColumn> 
            <GridForeignColumn Field=@nameof(Crypto.Symbol) HeaderText="Symbol" EditType="EditType.DropDownEdit" ForeignKeyValue="@nameof(PriceDto.Name)" ForeignDataSource="@Prices" Width="150"> 
                <EditTemplate> 
                    <SfComboBox ID=@nameof(PriceDto.Symbol) TValue="string" TItem="PriceDto" @ref="cbxSelectCoin" Placeholder="Select a coin" @bind-Value="@((context as Crypto).Symbol)" DataSource="@Prices" AllowFiltering="true"> 
                        <ComboBoxEvents TItem="PriceDto" TValue="string" ValueChange="SelectedCoinChanged" Filtering="args => OnFilter(cbxSelectCoin, args)"></ComboBoxEvents> 
                        <ComboBoxFieldSettings Text=@nameof(PriceDto.Name) Value=@nameof(PriceDto.Symbol)></ComboBoxFieldSettings> 
                    </SfComboBox> 
                </EditTemplate> 
            </GridForeignColumn> 
            . . . 
        </GridColumns> 
    </SfGrid> 
</div> 
 



Please let us know if you have any concerns. 

Regards, 
Rahul 



KH Khang August 10, 2021 06:19 PM UTC

Hi Rahul,


Thanks for the sample to help me solve the problem.

Now I understand more about the way that can combine grid and combobox controls.


Regards, 

Khang.



RN Rahul Narayanasamy Syncfusion Team August 11, 2021 05:15 AM UTC

Hi Khang, 
 
Thanks for the update. 
 
We are happy to hear that the provided solution was helpful to resolve the problem. Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon