We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding to data, choosing columns and only rendering unique rows?

Thread ID:

Created:

Updated:

Platform:

Replies:

149668 Dec 4,2019 09:52 PM UTC Dec 5,2019 04:25 PM UTC ASP.NET Web Forms 1
loading
Tags: Grid
Dynamic Benchmarking
Asked On December 4, 2019 09:52 PM UTC

Hello, 

We're building a reporting/excel export feature using the SF WebForms Grid.  Our end users will choose the columns, sorting and filtering criteria they want in their Excel file.

We're currently grabbing data via Linq2SQL which has quite a few columns and thousands of unique rows (considering all columns) and binding it to the grid.

Because of the nature of the source of the data (relational), when we only select subsets of columns, the visible data now has potentially many duplicates.   

Question:  Is there a way to have the Grid render (and also export) only the unique rows after column selection and filtering?

Example:

Take a hypothetical data set with 6 unique rows like this:

If I choose both columns, this is what I might see.

User  ProductCode
1          Bus
1          Car
2          Bus
3          Bus
4          Car
4          Train

If I were to use the column chooser and only select the "User" column,  I would want to see 4 rows:    

User
1
2
3
4

If I were to use the column chooser and only select the "ProductCode" column,  I would want to see only 3 rows:    

ProductCode
Bus
Car
Train


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On December 5, 2019 04:25 PM UTC

Hi Customer, 

Thanks for contacting Syncfusion Support. 

Query#:- Is there a way to have the Grid render (and also export) only the unique rows after column selection and filtering? 

We have checked your query and we have removed the duplicate row and bind the unique values to Grid using ActionComplete event of the Grid. In the ActionComplete event, when args.requestType as columnchooser, we can get the distinct values on using ej.dataUtil.distinct and the bind the newData using dataSource method of the Grid. 

Please refer to the code example:- 

<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > 
    <ClientSideEvents ActionComplete="complete" /> 
    <Columns> 
        <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="75"> 
        </ej:Column> 
        .     .      . 
         
</ej:Grid> 
 
<script> 
 
     function complete(args) { 
         if(args.requestType == "columnchooser"){ 
              var field = this.getColumnByHeaderText(args.visiblecolumns[0]).field; 
              var data = ej.dataUtil.distinct(args.model.dataSource, field); 
              var newData = []; 
              data.forEach(val => newData.push({[field]: val})); 
              var gridObj = $("#Grid").ejGrid("instance") 
              gridObj.dataSource(newData); 
        } 
    }</script> 
 
Note:- We have provided solution for single column.  

Refer to the API Link:- 

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon