Change Sorting of Grid Dropdown

Hi everybody,

   is there a way to influence the sorting of a grid dropdown. It seems to me, that it always sorts by text, which sometimes not usefull. For me it would help to have a switch to tell the dropdown control to leave the sorting alone because the initial sorting is OK or even better to be able to sort by text or value or perform NO sorting.

   regards

      Uwe

5 Replies

VN Vignesh Natarajan Syncfusion Team June 12, 2020 04:04 AM UTC

Hi Uwe,  
 
Thanks for contacting Syncfusion support.  
 
Query: “For me it would help to have a switch to tell the dropdown control to leave the sorting alone 
 
As we are quite unclear about your requirement, kindly share the following details about your query. 
 
  1. Are you referring the datasource of dropdownlist that appear in column while editing a record?
  2. Are you using ColumnTemplate or EditTemplate or EditType as DropDownListEdit to render Dropdownlist in Grid?
  3. Share the Grid code example.
  4. Can you please share more details about your requirement.
 
Above requested details will be helpful for us to validate the reported query at our end and provide solution as early as possible.  
   
Regards,
Vignesh Natarajan
 



RI Richard June 17, 2020 10:58 AM UTC

I'm interested in this too. 
I was expecting something like this to be ordered by DisplaySequence when editing. Sadly the ForeignKeyValue is overriding the order after it's fetched.

<GridForeignColumn TValue="AlarmType" Field="@nameof(Alarm.AlarmTypeId)" HeaderText="Type" ForeignKeyValue="AlarmType1" ForeignKeyField="Id">
            <SfDataManager Url="/odata/AlarmTypes?$select=Id,AlarmType1,DisplaySequence&$orderby=DisplaySequence" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
        </GridForeignColumn>




VN Vignesh Natarajan Syncfusion Team June 18, 2020 07:20 AM UTC

Hi Richard,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I was expecting something like this to be ordered by DisplaySequence when editing. Sadly the ForeignKeyValue is overriding the order after it's fetched. 
 
From your query we understand that you want to display the dropdown list data in different order (based on another column value). We suggest you to achieve your requirement using Edit params feature of Grid to change the Query property of DropDownList control.  
 
Refer the below code example.  
 
<SfGrid DataSource="@Orders" Height="250"> 
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridForeignColumn TValue="EmployeeData" Field=@nameof(Order.EmployeeID) Edit="@ShipNameEditParams" HeaderText="Employee Name" ForeignKeyValue="FirstName" Width="150"> 
            <Syncfusion.Blazor.Data.SfDataManager Url="https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Employees" CrossDomain="true" Adaptor="Adaptors.ODataAdaptor"> 
            </Syncfusion.Blazor.Data.SfDataManager> 
        </GridForeignColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
  
@code{ 
  
    public List<Order> Orders { getset; } 
    public object ShipNameEditParams = new 
    { 
@@params = new SfDropDownList<stringOrder>() { Query = new Syncfusion.Blazor.Data.Query().Sort("Title""descending") } 
}; 
 
  
For your convenience we have prepared a sample using above solution.  
 
 
Note: in above sample we have online services as datasource (without CRUD operation). So saving the data will not work properly. But while editing you can find the dropdownlist data in different order. Since it is sorted using Title column value. 
 
Refer our UG documentation for your reference 
 
 
Kindly get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 



RI Richard June 18, 2020 11:28 AM UTC

Thanks Vignesh,

I almost had it with this, but couldn't get the drop down to share the DataManager.

<GridForeignColumn TValue="AlarmType" Field="@nameof(Alarm.AlarmTypeId)" HeaderText="Type" ForeignKeyValue="AlarmType1" ForeignKeyField="Id">
            <ChildContent>
                <SfDataManager Url="/odata/AlarmTypes?$select=Id,AlarmType1" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
            </ChildContent>
            <EditTemplate>
                <SfDropDownList TItem="AlarmType" TValue="int" ID="AlarmTypeId" Value="@((context as Alarm).AlarmTypeId)" SortOrder="Syncfusion.Blazor.Lists.SortOrder.None">
                    <SfDataManager Url="/odata/AlarmTypes?$select=Id,AlarmType1,DisplaySequence&$orderby=DisplaySequence" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
                    <DropDownListFieldSettings Text="AlarmType1" Value="Id"></DropDownListFieldSettings>
                </SfDropDownList>
            </EditTemplate>
        </GridForeignColumn>

Your way worked perfect and the DataManager can be set to Offline too.

Thank you
Richard


VN Vignesh Natarajan Syncfusion Team June 19, 2020 09:02 AM UTC

Hi Richard,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Kindly get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon