Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all 7205 articles
Browse latest View live

How to show filter dialog before showing ListView

$
0
0

Scenario:

When a user executes a navigation item that displays a large ListView, the application should display a popup window that allows you to define a filter for this ListView before loading records in it. This filter dialog should remember the user's choice and provide the capability to select one of the stored filters.

Steps to implement:

1. Create a ListView model extender - IModelListViewExt - that adds the AdditionalCriteria property to the ListView model to store the filter selected by the user.

2. Implement the ViewFilterContainer class whose DetailView is used as a filter dialog.

3. Implement the ViewFilterObject class which is used to store filters.

4. Implement the ShowFilterDialogController which shows the filter dialog instead of displaying the ListView, and then shows the filtered ListView. To do this, subscribe to the ShowNavigationItemController.ShowNavigationItemAction.Execute event and replace the ListView from the e.ShowViewParameters.CreatedView property with the ViewFilterContainer DetailView. Then show the filtered ListView via the XafApplication.ShowViewStrategy.ShowView method.

5. Implement the NewViewFilterObjectController which sets the ObjectType property of the ViewFilterObject object created by the ViewFilterContainer.Filter lookup's New action.

ASP.NET:

6. Since the specified filters are stored in the AdditionalCriteria model property, it is necessary to save the value of this property between sessions. For this purpose, enable the database model differences store, as described in the How to: Store the Application Model Differences in the Database topic.

WinForms:

7. If your application uses MDI mode, note that when a View is already opened in an inactive tab, and you are opening it using the navigation panel again, the newly created View will not be used. Instead of this, the existing window will be activated, and your filter will be ignored. So, you will need to write additional code to filter the View displayed in this window. In this example, this is implemented through a custom Show View Strategy. See code from the WinShowFilterDialogController.cs and WinModule.cs files.

 

See Also:
How to: Use Criteria Property Editors
How to: Extend the Application Model and Schema
ShowNavigationItemController Class
Dialog Controller

Question Comments

Added By: Pablo Mazaeda 1 at: 11/13/2012 6:21:47 AM    

how do I do this for ASP.NET?

Added By: Mandeep Singh 10 at: 2/16/2014 6:57:38 AM    

Tried to download this Example. Returns the following error

Server Error in '/Support/Center' Application.

Added By: Anatol (DevExpress Support) at: 2/16/2014 11:49:17 PM    

This was likely a temporary issue. Please try to download the example once again.

Added By: Wieland Voß at: 3/4/2014 1:16:39 AM    

Hi Anatol,

how do we implement this solution for the asp.net environment? Simply importing DevExpress.ExpressApp.Web in ViewFilterContainerDetailViewController doesn't seem to meet our needs, since LookupPropertyEditor and LookupEdit are unknown.

Thank you
Wieland

Added By: Anatol (DevExpress Support) at: 3/4/2014 7:57:15 AM    

I have updated the example. Now its code is platform-independent and will work correctly in the ASP.NET project.

Added By: Wieland Voß at: 3/5/2014 7:32:50 AM    

Thank you for your quick answer!

The implementation works fine, but ,unfortunately, is way too slow in web-modus :(
It seems, that the generation of large lookup-lists (millions) during filter-creation takes a lot of time. Do you have any hint, how to prevent this behaviour?

Added By: Mauro Assis at: 9/18/2014 2:04:25 PM    

This is working great, but everytime I click a navigation item it creates a new "Default" filter. I'm using Web Application, would this matter?

Added By: Leandro Meneses 1 at: 9/21/2014 8:25:11 PM    

Hi i need filter only one listview, solutio apply for all views. thanks

Added By: Anatol (DevExpress Support) at: 9/24/2014 7:36:47 AM    Wieland, I have not reproduced any performance issue in ASP.NET applications. I have checked SQL queries sent by this example. When a navigation item is clicked, records from the ListView that is about to be displayed are not loaded until the filter dialog is closed. So, please provide a sample project reproducing the issue.

Mauro, the Default filter can be created several times in ASP.NET, because the AdditionalCriteria value stored in the View model is not stored between sessions. To solve this issue, either store the selected filter in the database rather than in the Application Model, or configure your application to store all model differences in the database, as shown in the following example: How to: Store Model Differences in Database.

Leandro, you can check the Id of the created view in the ShowNavigationItemAction_Execute event handler and show the filter dialog only for the required ListView.Added By: Mauro Assis at: 10/22/2014 6:54:34 AM    

I've got irt working now. I changed 1st line of GetFilterObject method in ShowFilterDialogController to:

CriteriaOperator criteria = CriteriaOperator.Parse("ObjectType = ?", objectType);

Because ASP.NET won't store last criteria used. But I have another request though. Now I want a Delete button to appear (like this <https://drive.google.com/file/d/0B1OV0NgtiOaXMTFkS19YaDdjRm8/view?usp=sharing&gt;) in the dialog, allowing to delete a filter. Currently it shows only "New" and "Clear".

Added By: Anatol (DevExpress Support) at: 10/23/2014 3:07:37 AM    

To process your recent post more efficiently, I created a separate ticket on your behalf: T164618: How to add a Delete button to the ASP.NET lookup editor. I will post my answer there soon.

Added By: Martin Brekhof 2 at: 10/23/2014 3:09:05 AM    

I must be missing something: it will not load in vs2012 with 13.2.9 (something about DXCore not loading) and the unpacked example could be platform independent but I only see a winforms implementatation. Any ideas?

Added By: Anatol (DevExpress Support) at: 10/23/2014 3:29:10 AM    

This example only has the WinForms version. In theory, since the code is platform-independent, it should work fine in ASP.NET after turning on the database model difference storage. However, we have not performed thorough testing of this scenario.
Please create a separate ticket regarding the issue with the Example Runner and describe your symptoms in greater detail. In addition, check whether or not this issue occurs when downloading other examples.

Added By: Gilson Appel at: 5/25/2015 10:17:38 AM    

Hello Anatol,

This approach isn't functional in TabbedMDI Mode for WinApplications. How can I create a new tab in my MainWindow?

--
Gilson

Added By: Anatol (DevExpress Support) at: 5/26/2015 11:36:56 AM    I have updated the example. Now it supports the TabbedMDI mode. I have changed the ShowFilterDialogController.dialogCotnroller_Accepting event handler and implemented the WinShowFilterDialogController class.Added By: Gilson Appel at: 5/26/2015 12:21:42 PM    

It's perfect, Anatol.

Thanks!

Added By: Phan Sin Tian at: 9/14/2017 11:36:39 PM    Can I have this solution translated to Entity Framework project?

How to use the ThemeResource extension to load resources from DevExpress themes dynamically

$
0
0
The ThemeResource extension allows you to load a resource from a currently applied DevExpress theme without specifying the theme name in xaml and reload the resource if a theme is changed. You can reference the resource in xaml as follows:
[XAML]
<BorderBackground="{dxi:ThemeResource {dxt:FloatingContainerThemeKey ResourceKey=FloatingContainerBackground}}"/>

 

See Also:
KA18580 - How to modify DX themes in WPF
K18542 - How to implement the ThemeMananger theme support in custom controls
T128436 - How to use DevExpress themes in a WPF Application

How to provide custom summary values for Total, Grand Total and ordinary cells for WPF PivotGridControl

$
0
0

This example is made based on the How to provide custom summary values for Total, Grand Total and ordinary cells example and illustrates how a cell type can be checked in the CustomSummary event handler. 
When the PivotGridControl.CustomSummary event is used to provide custom values for only Total or Grand Total cells, you can use the ColumnField and RowField properties to determine the kind of a processed cell. You can use the following rules to determine that a cell is being processed:

1. If ColumnField or RowField is null, it means that this is a Grand Total cell;
2. If both ColumnField and RowField are last fields in a corresponding area, this means that this is an ordinary cell.
3. In other cases, this is a Total cell.

NOTE
This example demonstrates how to determine the value type. To calculate summary values, you can use one of the following solutions:
1. Get calculated summary values using the SummaryValue property.
2. Calculate the value by iterating through DrillDownDataSource.
3. Calculate the value by summary values calculated for low level cells. This is the most complex approach demonstrated in the T158425: How to calculate Total cell values based on the low level Cell summary values example. In this example ASPxPivotGrid is used, but the approach should be similar. 

How to provide custom summary values for Total, Grand Total and ordinary cells

$
0
0

This example demonstrates how to determine the value type when you calculate custom summary values.
1. Set the data field's SummaryType property to Custom to perform calculations manually, by handling the CustomSummary event.
2. Use the PivotGridCustomSummaryEventArgs.ColumnField and PivotGridCustomSummaryEventArgs.RowField properties to determine the kind of a processed cell. You can use the following rules to determine that a cell is being processed:

    a. If ColumnField or RowField is null, it means that this is a Grand Total cell;
    b. If both ColumnField and RowField are last fields in a corresponding area, this means that this is an ordinary cell.
    c. In other cases, this is a Total cell.

See Also
E1877: How to Implement Custom Summary 
T158425: How to calculate Total cell values based on the low level Cell summary values
T555679: How to provide custom summary values for Total, Grand Total and ordinary cells (XtraPivotGrid)

Question Comments

Added By: Eurofins Lancaster Labs at: 10/12/2012 10:16:06 AM    

How can we override the bottom right grand total (total of grand totals)?

Added By: Eurofins Lancaster Labs at: 10/12/2012 11:17:42 AM    

Nevermind, I just had to loop through the items in the drill down data source.

How to provide custom summary values for Total, Grand Total and ordinary cells for WinForms PivotGridControl

$
0
0

This example demonstrates how to determine the value type when you calculate custom summary values.
1. Set the data field's SummaryType property to Custom to perform calculations manually, by handling the CustomSummary event. 
2. Use the PivotGridCustomSummaryEventArgs.ColumnField and PivotGridCustomSummaryEventArgs.RowField properties to determine the kind of a processed cell. You can use the following rules to determine that a cell is being processed:

    a. If ColumnField or RowField is null, it means that this is a Grand Total cell;
    b. If both ColumnField and RowField are last fields in a corresponding area, this means that this is an ordinary cell.
    c. In other cases, this is a Total cell.


See Also
E2592: How to provide custom summary values for Total, Grand Total and ordinary cells for ASPxPivotGrid
T555636: How to provide custom summary values for Total, Grand Total and ordinary cells for WPF PivotGridControl

How to: Bind the Grid to ICollectionView

How to implement server-side export in the ASP.NET Dashboard Control

$
0
0

This example demonstrates how to export a dashboard displayed in ASPxDashboard on the server side using the ASPxDashboardExporter class. The following API is used to implement this capability.
- The ASPxDashboard.CustomJSProperties server-side event is used to pass information about available dashboards to the client side.
- The ASPxClientDashboard.LoadDashboard method opens a selected dashboard.
- The ASPxClientDashboard.PerformDataCallback client-side method is used to pass the dashboard identifier and state to the server side. On the server side, the ASPxDashboard.CustomDataCallback event is used to obtain and parse these values.
- ASPxDashboardExporter.ExportToPdf is used to export the selected dashboard with the state passed from the client side.

Question Comments

Added By: Mahesh Jathar at: 9/18/2017 3:42:54 AM    How this functionality will be implemented in mvc? Please guide. 

How to bind BootstrapChart to filtered or sorted ASPxGridView data at runtime

$
0
0

This example demonstrates how to show filtered or sorted ASPxGridView data in BootstrapChart on a callback at runtime.

In page markup, enable ASPxGridView’s ShowFilterRow property to show FilterRow in it. Handle the DataBound event on the first page loadg to bind BootstrapChart data to ASPxGridView data.
Use the VisibleRowCount property to determine what ASPxGridView data is not filtered.

Then, handle ASPxGridView's AfterPerformCallback event to bind BootstrapChart data to ASPxGridView on the server side after a callback. In this event handler, check the e.CallbackName property to determine the sorting ("APPLYCOLUMNFILTER") or filtering ("SORT") callback command. Convert BootstrapChart data into the JSON format using the JavaScriptSerializer.Serialize function. Set the obtained JSON data string as ASPxGridView JSProperties to transfer data from the server to the client.

Handle ASPxGridView's client-side EndCallback event for client-side data binding on a callback initiated by data filtering or sorting. Call the JSON.parse function to obtain transferred ASPxGridView data as a JavaScript object.

To set BootstrapChart's data source on the client side, use BootstrapChart’s private BootstrapClientChart.SetDataSource method.


How to: Display Unbound Data

$
0
0

This example shows how to add an unbound column to the Grid Control.

How to: Summarize Empty Cells

$
0
0

The following example demonstrates how to use custom summaries to count the total number of empty cells in a grid column.

How to: Implement Custom Grouping

$
0
0

This example shows how to group rows using custom rules. When grouping by the 'Unit Price' column, the rows in this column that have values between 0 and 10 should be combined into a single group. Rows whose values fall between 10 and 20 should be combined into another group, etc.

How to: Implement Custom Sorting

$
0
0

This example demonstrates how to implement custom sorting in the Grid Control.

Change the filter combobox list values based on the value of another filter combobox

$
0
0

This example demonstrates how to changed the 'city' filter combobox values based on the 'country' filter combobox.

UPDATED:

Starting with version 16.1 we optimized bindings for a combo box column in ASPxGridView. So, if a data source is changed, it is required to call the RequireDataBinding method to apply these changes. 

Question Comments

Added By: Sinan EGE 1 at: 6/19/2015 5:56:41 PM    

An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code

protected void dgListe_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
       {
           if (e.Column.FieldName == "ilceid")
           {
               ASPxComboBox cmb = e.Editor as ASPxComboBox;
               cmb.ClientInstanceName = "cmb2";
               cmb.Callback += new DevExpress.Web.CallbackEventHandlerBase(cmb_Callback);

               cmb.DataSourceID = "dsIlce";

           }
           else if (e.Column.FieldName == "sehirid")
           {
               ASPxComboBox cmb = e.Editor as ASPxComboBox;
               cmb.ClientInstanceName = "cmb1";
               cmb.ClientSideEvents.SelectedIndexChanged = "function (s, e) { cmb2.PerformCallback(s.GetValue()); }";
               cmb.ClientSideEvents.Init = "function (s, e) { cmb2.PerformCallback(s.GetValue()); }";
           }
       }

       void cmb_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
       {
           ASPxComboBox cmb = sender as ASPxComboBox;

           if (String.IsNullOrEmpty(e.Parameter))
               cmb.Items.Clear();
           else
           {
               dsIlce.SelectParameters[0].DefaultValue = e.Parameter;
               cmb.DataBindItems();
           }
       }

UploadControl with Model Binding Support - Registration Form

$
0
0
This example illustrates how to bind UploadControl (its posted files) with a Model property:
- Set the corresponding Model property of the "IEnumerable<UploadedFile>" type;
- Set the UploadControlSettings.Name property equal to this related Model property.
Question Comments

Added By: Twjones at: 9/18/2017 4:07:15 PM    Why does model binding fail when with the Upload Control when:

settings.EnableDragAndDrop = True ?

How to perform the Search operation for multiple locations

$
0
0
The Search operation is executed in an asynchronous manner and the next Search operation cannot be invoked while waiting for the result from the previous Search request. To resolve this issue, include subsequent Search method calls into the SearchCompleted event handler.
Question Comments

Added By: Jordi Román at: 9/19/2017 1:41:51 AM    This method is very slow when you search for a lot of records. Isn't there a faster method?


Oh, thank you.

How to replace DashboardSqlDataSource with DashboardObjectDataSource and filter loaded data manually

$
0
0

DashboardSqlDataSource allows requesting data in two ways:
1. Direct database connection: Server Mode.
2. In-memory data processing: Client Mode.

The first approach works if you configure the data source using the Query Builder. In this case, it is possible to add a custom filter expression to filter requested data using the CustomFilterExpression event.
If you load data using a custom SQL query or a stored procedure, only Client Data Processing Mode is supported. This example demonstrates how to filter data requested from a database manually and pass it to a dashboard as DashboardObjectDataSource.
To accomplish this task, handle the DashboardLoaded event and replace the target DashboardSqlDataSource queries with new DashboardObjectDataSources.
Then, handle the DataLoading event to provide data to the new object data sources. To learn how to request data using DashboardSqlDataSource, refer to the T347509: How to get data from the Dashboard DataSource and convert it to DataTable thread. 
 

How to implement BootstrapGridView context menu with items similar to ASPxGridView

$
0
0
This example demonstrates how to implement BootstrapGridView context menu with items similar to ASPxGridView. These items include CRUD operations to Insert, Update, Delete data in BootstrapGridView's data source, operations to enable or disable FilterRowSearchPanel and GroupPanel, and operations to change Visible property of BootstrapGridView's columns.

The Javascript dictionary object is used to save BootstrapGridView's elements visibility states on client side.

In page markup, handle the BootstrapClientGridView.Init event and add event handler for contextmenu event of BootstrapGridView's main element. This event handler is used to set the Enabled and Text properties of BootstrapPopupMenuitems depending on BootstrapGridView's elements visability and clicked item index. To get the clicked item index, perform the following steps:
1) Call ASPxClientUtils.GetEventSource method to obtain the object that fired the current event.
2) Convert the object to jQuery object.
3) In page markup, set the CssClasses.Row property to the "grid-row" and pass that parameter to the parents method of the jQuery object to get GridView row javascript object.
4) Use the GetPageIndex method and a private BootstrapClientGridView's pageRowSize field of with applied to the jQuery GridView row object index method.
To receive the clicked BootstrapGridView item's ID on the client side, use BootstrapClientGridView.GetRowKey method.

Then handle the BootstrapGridView's CustomCallback event to add the current BootstrapGridView's elements visability states to its JSProperties, and to transfer them from the server to the client. Handle BootstrapClientGridView.EndCallback event to get access to its JSProperties and to write updated BootstrapGridView's elements visability states to the javasript dictionary.

Handle the BootstrapClientPopupMenu.ItemClick event to perform an action depending on the selected item. Use the ASPxClientMenuItem.name property to determine the selected item name and switch the applied action.
To manipulate BootstrapGridView data on the client side use AddNewRowStartEditRow and DeleteRow BootstrapClientGridView's methods.
To change BootstrapGridView's elements visability states, call the BootstrapClientGridView.PerformCallback method.

How to replace a data source that uses direct database connection with a new one which is bound to a list of objects

$
0
0

Update:
This example is now obsolete. Refer to the following examples demonstrating how to implement this functionality in the newer control versions:
WinForms: T556647: How to replace DashboardSqlDataSource with DashboardObjectDataSource and filter loaded data manually
ASP.NET: T556759: How to replace DashboardSqlDataSource with DashboardObjectDataSource and filter loaded data manually


This example demonstrates how to replace Sql Data Source with Object Data Source using the DashboardLoaded event. This approach can be used in WinForms, ASP.NET and MVC projects. Generally, all you need is to create a new data source and bind all existing items to it using the DataDashboardItem.DataSource Property. It is necessary that data members of the new data source match data members of the old one.

How to replace DashboardSqlDataSource with DashboardObjectDataSource and filter loaded data manually

$
0
0
DashboardSqlDataSource allows requesting data in two ways:
1. Direct database connection: Server Mode.
2. In-memory data processing: Client Mode.

The first approach works if you configure the data source using the Query Builder. In this case, it is possible to add a custom filter expression to filter requested data using the CustomFilterExpression event.
If you load data using a custom SQL query or a stored procedure, only Client Data Processing Mode is supported. This example demonstrates how to filter data requested from a database manually and pass it to a dashboard as DashboardObjectDataSource.
To accomplish this task it is necessary to define a custom DashboardStorage class and implement the LoadDashboard method to update loaded dashboards and replace the target DashboardSqlDataSource queries with new DashboardObjectDataSources.
Then, handle the DataLoading event to provide data to the new object data sources. To learn how to request data using DashboardSqlDataSource, refer to the T347509: How to get data from the Dashboard DataSource and convert it to DataTable thread. 

How to: Implement Conditional Formatting for Rows Using Templates

$
0
0
This example illustrates how to use templates to alternate the row background color.
Viewing all 7205 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>