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

How to: Build Dock UI According to MVVM Pattern Using LayoutAdapter


How to: Save and Restore the DockLayoutManager Layout

$
0
0

DockLayoutManager provides several methods to save and restore layout settings:
- SaveLayoutToStream;
- SaveLayoutToXml;
- RestoreLayoutFromStream;
- RestoreLayoutFromXml.

Note that item names are used to identify them when saving/restoring a layout, so it will be necessary to set names for all DXDocking items to make sure that settings will be restored properly.

It may happen that some panels were added/removed after the DockLayoutManager's layout was saved. In this scenario, DockLayoutManager will remove panels that are not present in the saved layout and ignore saved settings for items that do not exist anymore. To change this behavior, set the following options:
- To re-create panels that are present in the saved layout, set RestoreLayoutOptions.RemoveOldPanels to False.
- Set RestoreLayoutOptions.AddNewPanels to True to maintain panels that are not present in the saved layout.

Please note that the DockLayoutManager's methods save settings only of its groups and panels. To save settings of embedded controls, use WorkspaceManager as shown at How to save and restore settings of all controls that are present in the UI.

See also:
How to serialize a particular panel layout
How to serialize custom panels and their properties
How to save and restore settings of all controls that are present in the UI

How to: Save and Restore Settings of All Controls That Are Present in the UI

How to: Serialize DockLayoutManager When TabbedDocumentUIService Is Used

$
0
0

Some of DockLayoutManager’s panel groups can contain documents that were created from ViewModel with IDocumentManagerService. To serialize and restore them correctly, it is necessary to perform the following steps.

Item names are used to identify items when saving/restoring the layout. For this reason, it will be necessary to set unique names for all DockLayoutManager panels. In the current scenario, this can be done by setting the DocumentPanel.BindableName property in the TabbedDocumentUIService.DocumentPanelStyle.

Another important point is that the DockLayoutManager's saving/restoring mechanism is not the XamlWriter alternative - it does not save/restore content of its panels. It will be necessary to additionally restore it. In this example, we used the following approach:
1. Before saving layout settings, serialize all documents created from the ViewModel.
2. Before restoring settings, recreate all documents.

How to: Embed a Bar into a Dock Panel

$
0
0

This example shows how to embed a bar from the DXBars library into a dock panel.

Dock panels embed bar containers at their top edges, allowing bars to be displayed in these containers. To add a bar to a dock panel's bar container, the name of the target bar container is assigned to the Bar.DockInfo.ContainerName property. This name matches the name of the LayoutPanel.HeaderBarContainerControlName property's value.

How to: Customize a Panel's Context Menu via Actions

How to: Use Built-In DXDocking Commands in Custom Buttons

$
0
0

The DXDocking library provides a set of commands on dock panels. These are declared in the DockControllerCommand class. For instance, the Close command allows you to close a specific dock panel. The Activate command activates a dock panel.
This example shows how to associate the Close command with a button. When an end-user clicks the button, the active dock panel is closed.

How to: Load an External Window or UserControl into a DocumentPanel

$
0
0

You can define a Window, Page or UserControl in external XAML files and then, with DXDocking, load their contents into DocumentPanel objects.

This example demonstrates how to load an external Window and UserControl into DocumentPanels.

In the example three approaches are demonstrated:

1) The contents of MyWindow.xaml is loaded into a DocumentPanel at design time (in XAML) via the DocumentPanel.Content property. The Content property accepts a Uri object, which must refer to a XAML file defining a Window, Page or UserControl.

[XAML]
<dxdo:DocumentPanelx:Name="docPanel2"Caption="Panel 2"Content="{dxdo:RelativeUri UriString=CustomWindows\\MyWindow.xaml}"/>


2) The DocumentPanel.Content property is set with a Uri object at runtime:

[C#]
docPanel1.Content=newUri(@"CustomWindows\MyWindow1.xaml",UriKind.Relative);

 

3) The DockLayoutManager.DockController.AddDocumentPanel method creates a new DocumentPanel object and loads the contents of an external XAML file into the created panel.

[C#]
panel1=dockLayoutManager1.DockController.AddDocumentPanel(documentGroup1,newUri(@"CustomWindows\UserControl1.xaml",UriKind.Relative));panel1.Caption="Document "+(ctr++).ToString();

In the example, the XAML file defines a UserControl object. The loaded UserControl is accessed via the DocumentPanel's Control property and then a method on the UserControl is invoked.

[C#]
//...(panel1.ControlasUserControl1).SetDataContext(imageInfo);

You can see this in action by clicking the "Set DataContext for UserControl" button in the example.

Question Comments

Added By: Sudha Raman at: 10/22/2013 9:21:47 AM    

Hi,

 I am following the same approach in my project. My question is how to close the Usercontrol from Button click event of it.(not using the 'X' on right corner- usercontrol unloaded event).

Thanks
Sudha.

Added By: Alex Zeller (DevExpress) at: 10/23/2013 1:00:47 AM    

Hi,
If you have a button within a UserControl displayed within a DocumentPanel, you can use the Button.Click event to close the current DocumentPanel:
private void button1_Click(object sender, RoutedEventArgs e) {
    DockLayoutManager dm = DockLayoutManager.GetDockLayoutManager(this);
    dm.DockController.Close(dm.ActiveDockItem);
}
Thanks, Alex.

Added By: Cotza Andrea at: 11/20/2013 1:56:14 AM    

Hi,

 I've a windows (MDI) with buttons (save, new ecc.) and document panel with loaded windows at runtime. I need to send commands from child windows to MDI window (enable/disable buttons). How can I do?

Thanks, Andrea.


How to: Create a Navigation Menu with TreeView Similar to One Used in Outlook 2003 Using SideBarView

$
0
0
SideBarView is a NavBarControl's view that was designed to simulate the Outlook 2003 navigation bar. SideBarView can display only one group at a time. To show custom content in a group instead of NavBarItems, set NavBarGroup.DisplaySource to "Content". To disable the built-in group scrolling so that controls can use their own scrolling mechanism, set the ScrollingSettings.ScrollMode attached property to "None".

How to: Use OfficeNavigationBar with NavBarControl to Navigate Between Views

$
0
0

This example demonstrates how to populate OfficeNavigationBar from NavBarControl and navigate between different views when items in OfficeNavigationBar are selected. To bind OfficeNavigationBar to NavBarControl, set the NavigationClient property to an instance of NavBarControl. OfficeNavigationBar will be automatically populated with groups in NavBarControl. When an item in OfficeNavigationBar is clicked, a corresponding group from NavBarControl will be selected.
To navigate between views, the NavigationFrame control is used. This control is bound to FrameNavigationService which can be accessed from the view model to perform navigation.

How to: filter a XtraReport Parameter's lookup in XAF

$
0
0

Scenario
When you need to use a parameter of a type with many records in your report, it is convenient to filter the parameter's lookup.

While in the XAF WinForms application this option is built in the lookup editor, the ASP.NET parameter editors don't provide the filtering capability.

Steps to implement

You can provide the filter for the lookup parameter using an additional data source.

1. Add another Data Sources for Reports V2 to your report from the toolbox and set its ObjectTypeName to the type of the parameter.

2. Set the Criteria property of the data source to the required filter.

3. Add a parameter with the Type property set to key type. Enable "Support the collection of standard values" and set the DataSource, Display Member and Value Member properties.

Also, it is possible to use an approach from the "Cascading Parameters" part of the Parameters Overview article to provide a filter on the client side instead of setting the Criteria property of the data source.


How to: Configure a Chart for Printing

$
0
0

This example demonstrates how to configure chart options that are used for printing.

How to apply default filtering to master filters in DashboardViewer

$
0
0
The following example shows how to apply default filtering to master filter items using API of DashboardViewer. In this example, default filtering is applied to the following dashboard items.
- The SingleFilterDefaultValue event is handled to apply filtering to the Grid dashboard item with the Single Master Filter enabled.
- The FilterElementDefaultValues event is handled to select required values in the Tree View filter element.
- The RangeFilterDefaultValue event is used to select the specified date range in the Range Filter.

How to create a custom Table Of Contents for merged reports with page indexes

$
0
0
This code example illustrates how to create a custom "Table Of Contents" in a separate report.
It is necessary to create links between bricks of merged reports manually, after the reports are merged. Get the required bricks from the report using NestedBrickIterator and use the VisualBrick.NavigationPair property to create a link. To provide page indexes for such links, collect "page" bricks to a separate collection and then modify the VisualBrick.Text property value based on Target.Page.Index.

How to: Build Outlook Navigation Menu Using OfficeNavigationBar and NavBarControl with TreeView on the Left

$
0
0

In Outlook 2013, you may notice a special menu at the bottom for navigation between different views. You can build such a menu with DevExpress controls using OfficeNavigationBar and NavBarControl. OfficeNavigationBar takes all groups from NavBarControl and displays them in one line. To bind OfficeNavigationBar to NavBarControl, use the OfficeNavigationBar.NavigationClient property. Please note that to display OfficeNavigationBar, it's necessary to set NavBarControl.Compact to false.

OfficeNavigationBar supports Peek Forms (popups displayed when you hover over an item). 


To enable them, set ShowPeekFormOnItemHover to true and specify the PeekFormTemplate property.

Note that to display custom content in NavBarGroups, it's necessary to set NavBarGroup.DisplaySource to "Content". It also makes sense to disable built-in group scrolling so that TreeView can use its own scrolling mechanism. To accomplish this task, set GroupScrollMode to "None".


OBSOLETE - How to implement multi-row editing in the ASP.NET ListView

$
0
0

NOTE: Starting with version 15.2, our ASPxGridListEditor supports the Batch Edit Mode out of the box. To enable it, set the IModelListView.AllowEdit property to True and the IModelListViewWeb.InlineEditMode property to Batch in the Model Editor, as described in the List View Edit Modes topic.


For versions prior to 15.2:

There are several examples on how to implement this functionality in the ASPxGridView without XAF. From my point of view, the How to perform ASPxGridView instant updating using different editors in the DataItem template example is the most appropriate for XAF, because:

- this approach can be easily implemented using runtime code

- we already use DataItem templates to show data in grid cells.


All functionality is implemented in a single controller - the MultiRowEditingController. It performs the following operations:

1. Creates an ASPxCallback control and adds it to a page. This control is used to send callbacks from client-side editors used in grid cells.

2. Replaces the default DataItemTemplate with a custom one (EditItemTemplate). The custom template is required to show editors for the user input in grid cells. This template is based on the DataItemTemplate class used in XAF by default. The only difference is that controls from this template are always in the Edit mode.

3. Assigns the client-side script that performs a callback when the value is changed to the editors added to grid cells via the custom DataItemTemplate. This is done in the editor's Init event handler, because at this moment, the NamingContainer that contains the key of the bound object is available.

4. Handles the callback sent from the client side and changes the value of a corresponding object's property.


I recommend that you review the following help topics for additional information:

Access Grid Control Properties
ASPxGridView.Templates Property
How to use custom ASPxGridView template in a Web XAF application


Important notes
We have not tested this solution under all possible scenarios, so feel free to modify and test the code to better suit your needs. It this example and its current limitations do not meet your requirements, check out the How to enable fast data entry in multiple rows for ListView on the Web (ASPxGridListEditor)? thread for alternative solutions.

Question Comments

Added By: Yuriy Konytskyy at: 6/3/2013 3:44:39 AM    

I doesn't work in v12.2.10

Added By: Anatol (DevExpress Support) at: 7/1/2013 4:19:13 AM    

I have updated the example. Please see implementation details for version 13.1.

Added By: Sandro Welter (Intelligix) at: 7/5/2013 3:02:00 PM    

I'm getting the error below.

The error occurred:
     Type: NullReferenceException
     Message: Object reference not set to an instance of an object.
     Data: 0 entries
     Stack trace:

Added By: Anatol (DevExpress Support) at: 1/10/2014 8:32:12 AM    

The NullReferenceException issue is solved.

Added By: PHN at: 1/30/2014 10:55:55 AM    

Hi,
I have some modifications to support ASPxDateTimePropertyEditor,ASPxLookupPropertyEditor:

using System;
using System.Linq;
using System.ComponentModel;
using System.Web.UI;

using DevExpress.ExpressApp.Web.Editors.ASPx;
using DevExpress.Web.ASPxGridView;
using DevExpress.ExpressApp.Web;
using DevExpress.ExpressApp.Editors;
using DevExpress.Web.ASPxClasses;
using DevExpress.ExpressApp.DC;
using DevExpress.Web.ASPxCallback;
using DevExpress.ExpressApp.Model;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Xpo;
using DevExpress.ExpressApp;

namespace WebExample.Module.Web
{
    [ListEditor(typeof(object), false)]
    public class MultiEditASPxGridListEditor : ASPxGridListEditor
    {
        const String CallbackArgumentFormat = "function (s, e) {{ {0}.PerformCallback(\"{1}|{2}|\" + {3}); }}"; // ASPxCallback, key, fieldName, value
        public MultiRowEditASPxGridListEditor(IModelListView model)
            : base(model) { }
        ASPxCallback callback;
        protected override object CreateControlsCore()
        {
            Panel panel = new Panel();
            callback = new ASPxCallback();
            callback.ID = ObjectTypeInfo.Type.Name + "aspxCallback1";
            callback.ClientInstanceName = ObjectTypeInfo.Type.Name + "_callback1";
            callback.Callback += new CallbackEventHandler(callback_Callback);
            panel.Controls.Add(callback);
            ASPxGridView grid = (ASPxGridView)base.CreateControlsCore();
            grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared);
            panel.Controls.Add(grid);
            return panel;
        }
        
        void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
        {
            if (e.DataColumn is GridViewDataColumnWithInfo && IsColumnSupported(((GridViewDataColumnWithInfo)e.DataColumn).Model))
            {
                e.Cell.Attributes["onclick"] = RenderHelper.EventCancelBubbleCommand;
            }
        }

        protected override ITemplate CreateDataItemTemplate(IModelColumn columnInfo)
        {
            if (IsColumnSupported(columnInfo))
            {
                EditModeDataItemTemplate editModeTemplate = (EditModeDataItemTemplate)CreateDefaultColumnTemplate(columnInfo, this, ViewEditMode.Edit);
                editModeTemplate.PropertyEditor.ImmediatePostData = false;
                editModeTemplate.CustomCreateCellControl += new EventHandler<DevExpress.ExpressApp.Web.Editors.CustomCreateCellControlEventArgs>(editModeTemplate_CustomCreateCellControl);
                return editModeTemplate;
            }
            else
            {
                return base.CreateDataItemTemplate(columnInfo);
            }
        }
        
        void editModeTemplate_CustomCreateCellControl(object sender, DevExpress.ExpressApp.Web.Editors.CustomCreateCellControlEventArgs e)
        {
            if (e.PropertyEditor.Editor is ASPxWebControl)
            {
                e.PropertyEditor.Editor.Init += new EventHandler((s, args) => Editor_Init(s, args, e.PropertyEditor.Editor));
            }
            else if (e.PropertyEditor is ASPxLookupPropertyEditor)
            {
                ASPxLookupPropertyEditor editor = e.PropertyEditor as ASPxLookupPropertyEditor;
                editor.DropDownEdit.DropDown.Init += new EventHandler((s, args) => Editor_Init(s, args, e.PropertyEditor.Editor));
            }
            
        }

        void Editor_Init(object sender, EventArgs e,WebControl baseEditor)
        {
            ASPxWebControl editor = (ASPxWebControl)sender;
            editor.Init -= new EventHandler((s, args) => Editor_Init(s, args, baseEditor));
            // Uncomment to remove editors borders
            //editor.Border.BorderStyle = BorderStyle.None;
            GridViewDataItemTemplateContainer container = baseEditor.NamingContainer as GridViewDataItemTemplateContainer;
            var columnInfo = container.Column as GridViewDataColumnWithInfo;
            editor.SetClientSideEventHandler("ValueChanged", String.Format(CallbackArgumentFormat,
                callback.ClientInstanceName, container.KeyValue, columnInfo.Model.PropertyName, editor is ASPxDateEdit ? "s.GetText()" : "s.GetValue()"));
        }

        void callback_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            String[] p = e.Parameter.Split('|');
            Object key = TypeDescriptor.GetConverter(ObjectTypeInfo.KeyMember.MemberType).ConvertFromString(p[0]);
            IMemberInfo member = ObjectTypeInfo.FindMember(p[1]);
            Object value = null;
            if (typeof(IXPSimpleObject).IsAssignableFrom(member.MemberType))
            {
                Type memberKeyType = XafTypesInfo.Instance.FindTypeInfo(member.MemberType).KeyMember.MemberType;
                int index1 = p[2].LastIndexOf("(");
                int index2 = p[2].LastIndexOf(")");
                if (index1 > 0 && index2 > index1)
                {
                    string memberKeyText = p[2].Substring(index1 + 1, index2 - index1 - 1);
                    value = ObjectSpace.GetObjectByKey(member.MemberType, Convert.ChangeType(memberKeyText, memberKeyType));
                }
            }
            else
            {
                value = TypeDescriptor.GetConverter(member.MemberType).ConvertFromString(p[2]); ;
            }
            object obj = ObjectSpace.GetObjectByKey(ObjectTypeInfo.Type, key);
            member.SetValue(obj, value);
            ObjectSpace.CommitChanges();
        }

        private Type[] supportedPropertyEditorTypes()
        {
            return new Type[]{
                typeof(ASPxStringPropertyEditor),
                typeof(ASPxIntPropertyEditor),
                typeof(ASPxBooleanPropertyEditor),
                typeof(ASPxEnumPropertyEditor),
                typeof(ASPxDateTimePropertyEditor),
                typeof(ASPxLookupPropertyEditor)
            };
        }

        protected virtual bool IsColumnSupported(IModelColumn model)
        {
            if (model.GroupIndex >= 0)
            {
                return false;
            }
            foreach (Type type in supportedPropertyEditorTypes())
            {
                if (type.IsAssignableFrom(model.PropertyEditorType))
                {
                    return true;
                }
            }
            return false;
        }
        // Sorting and grouping are not supported
        protected override ColumnWrapper AddColumnCore(IModelColumn columnInfo)
        {
            ASPxGridViewColumnWrapper columnWrapper = (ASPxGridViewColumnWrapper)base.AddColumnCore(columnInfo);
            if (IsColumnSupported(columnWrapper.Column.Model))
            {
                columnWrapper.Column.Settings.AllowSort = DevExpress.Utils.DefaultBoolean.False;
                columnWrapper.Column.Settings.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
            }
            return columnWrapper;
        }
    }
}

Added By: Anatol (DevExpress Support) at: 1/31/2014 12:04:45 AM    

Thank you for sharing your code. It looks good. I hope it will be useful for others.

Added By: Apostolis Bekiaris (DevExpress) at: 2/17/2014 7:12:23 AM    

Added in eXpandFramework 13.2.7.4

Added By: HEUNGGI LEE at: 6/4/2014 6:10:47 AM    

Hi,
Is it possible to set width length on each column in GridView? It is ugly...especially Character field grid width is too narrow ..

Added By: Anatol (DevExpress Support) at: 6/5/2014 7:42:58 AM    Yes, this is possible - see Adjust column width in listviews on the Web.Added By: HEUNGGI LEE at: 6/18/2014 9:48:18 PM    

Hi PHN,
I tried with your code but list grid view does not show correctly row items. Last row has same pointer with before last row item.

Added By: HEUNGGI LEE at: 12/28/2014 2:51:20 AM    

Hi,
this code does not work in 14.2.....

Added By: Anatol (DevExpress Support) at: 12/29/2014 6:10:51 AM    

Thank you for your report. It is necessary to turn on Data Item Templates in MultiEditASPxGridListEditor using the UseASPxGridViewDataSpecificColumns property, since they are disabled in version 14.2 by default. I have updated the example.

Added By: Anatol (DevExpress Support) at: 2/3/2015 8:50:08 AM    I have found that this quick fix was insufficient to make this example work correctly in version 14.2. I have replaced it with another fix. A new version is already available.Added By: Warren Connors 4 at: 4/3/2015 12:31:48 PM    

Would it be possible for you guys to update your example runner with a version that shows the date picker and dropdownlist functionality? That would solve 99% of customer needs (as it would solve my current requirement).

Added By: Dennis (DevExpress Support) at: 4/6/2015 3:05:32 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T227338: Example Runner: update with a version that shows the date picker and dropdownlist functionality. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Custom GridControl - How to provide the capability to hide group footer rows at a specific group level

$
0
0

This example demonstrates how to implement the ShowGroupFooter event which allows hiding group footer rows at a specific group level. To specify which rows should be hidden, set the e.Visible parameter to false. The e.FooterLevel parameter specifies the grouping level at which footer visibility should be processed.

Question Comments

Added By: Stécy at: 7/7/2014 8:00:40 AM    

Great solution.

Is it possible to show the footer for a collapsed level?

Added By: Svetlana (DevExpress Support) at: 7/7/2014 11:36:15 PM    Hi, 

I have extracted your inquiry to a separate ticket . Please refer to it. Added By: Panayiotis Anastasiou at: 1/6/2016 3:19:36 AM    

Thanks for your sample Dimitros. Your sample seems to be working the way we would like the gridcontrol to work, but then again you have used your own myGridControl class and a batch of other classes in order to achieve this behaviour. Therefore, we are using a very large scale project and we cannot convert to a different gridcontrol (myGridControl1) and a "batch of other classes", like ShowGroupFooter, in order to accomplish this throughout our project. So, as i understood, the only way to accomplish this is through your sample classes, so in such case, we need to convert gridcontrols on every form to your one?

Added By: Gosha (DevExpress Support) at: 1/6/2016 4:07:42 AM    

Hi Panayiotis,

Yes, it's necessary to use a custom GridControl to achieve this functionality. So, you need to replace default GridControls with custom ones. Since the Grid consists of the GridControl and its GridView, replace GridControl with MyGridControl and GridView with MyGridView. I suggest you use the Find All Visual Studio feature not to miss any GridControl.

How to create user folders within the Customization Form

$
0
0

The following example shows how to group fields in the Customization Form by putting them in user-defined folders.

In this example, the Customization Form is invoked by calling the PivotGridControl.FieldsCustomization method.
To enable displaying user folders, the PivotGridOptionsViewBase.GroupFieldsInCustomizationWindow property is set to true.

To create a folder for the Person field, the fieldSalesPerson.DisplayFolder property is set to "Employees". To create the main folder and nested folders for Product Name and Category Name fields, the fieldProductName.DisplayFolder property is set to "Products\\Name" and fieldCategoryName.DisplayFolder "Products\\Category" respectively.

Question Comments

Added By: Candy lei at: 1/6/2016 11:44:11 PM    

The project running with version 15.2.4 will occurs error

Added By: Alex (DevExpress Support) at: 1/7/2016 1:48:09 AM    

We have already fixed this issue in the context of the XtraPivotGrid customization form throws NullReferenceException in OLAP mode report. Install a hotfix from that thicket and let us know whether it helps.

How to add DragAndDrop capability to the detail grid

$
0
0

This example demonstrates how to add the DragAndDrop capability to the detail grid.

Our detail grid with DataControlDetailDescriptor doesn't support drag and drop. To provide this capability in this sample, we create a GridDragDropManager class descendant and override the CalcDraggingRows method to obtain a selected row. Then, we subscribe to the GridDragDropManager's DragOver and Drop events. When Drop is raised, we calculate to which position we must insert a selected row. 

Question Comments

Added By: nikoloo4 at: 9/29/2015 4:35:05 AM    

The example doesn't build.
Problems:
1. BanDrop method is not implemented.
2. There is no GridControl variable in the class.

Could you please take a look at it?

Added By: Kirill (DevExpress Support) at: 10/1/2015 1:11:00 AM    

Hello,
Would you please clarify what version of our controls you use? I've tested this example on versions 14.1.8, 14.1.11, 14.2.4, 14.2.7, 15.1.4 and 15.1.7 - the example is built correctly on these versions.


Thanks,
KirillAdded By: Merlijn at: 1/7/2016 2:37:50 AM    

Had the same issue as nikoloo4, using version 15.1.2, after upgrading to 15.2.4 it seems to build.

ASPxGridView - How to update total summaries on the client side in Batch Edit mode

$
0
0

This example demonstrates how to update total summaries on the client side when ASPxGridView is in Batch Edit mode. To implement the required task, perform the following steps:

1. Add a total summary item for a required column. The ASPxSummaryItem.Tag property is used to find this summary item on the server side: 

[ASPx]
<SettingsShowFooter="true"/><TotalSummary><dx:ASPxSummaryItemSummaryType="Sum"FieldName="C2"Tag="C2_Sum"/></TotalSummary>

 2. Replace the summary item with a custom Footer template:

[ASPx]
<dx:GridViewDataSpinEditColumnFieldName="C2"><FooterTemplate> Sum =<dx:ASPxLabelID="ASPxLabel1"runat="server"ClientInstanceName="labelSum"Text='<%# GetTotalSummaryValue() %>'></dx:ASPxLabel></FooterTemplate></dx:GridViewDataSpinEditColumn>

 The GetTotalSummaryValue method is used to get the actual summary value when the grid is initialized:

[C#]
protectedobjectGetTotalSummaryValue(){ASPxSummaryItemsummaryItem=Grid.TotalSummary.First(i=>i.Tag=="C2_Sum");returnGrid.GetTotalSummaryValue(summaryItem);}

 3. Handle the grid's client-side BatchEditEndEditing event to calculate a new summary value and set it when any cell value has been changed:

[JScript]
function OnBatchEditEndEditing(s, e){var originalValue = s.batchEditApi.GetCellValue(e.visibleIndex, "C2");var newValue = e.rowValues[(s.GetColumnByField("C2").index)].value; var dif = newValue - originalValue; labelSum.SetValue((parseFloat(labelSum.GetValue()) + dif).toFixed(1));}

4. Finally, replace standard Save changes and Cancel changes buttons with custom buttons to refresh a summary value when all modifications have been canceled:

[ASPx]
<Templates><StatusBar><divstyle="text-align: right"><dx:ASPxHyperLinkID="hlSave"runat="server"Text="Save changes"><ClientSideEventsClick="function(s, e){ gridView.UpdateEdit(); }"/></dx:ASPxHyperLink><dx:ASPxHyperLinkID="hlCancel"runat="server"Text="Cancel changes"><ClientSideEventsClick="function(s, e){ gridView.CancelEdit(); gridView.Refresh(); }"/></dx:ASPxHyperLink></div></StatusBar></Templates>


See Also:

ASPxGridView - Batch Edit - How to calculate values on the fly 
ASPxGridView - Batch Edit - How to calculate unbound column and total summary values on the fly 

ASP.NET MVC Example:
GridView - How to update total summaries on the client side in Batch Edit mode

Question Comments

Added By: Dhaval.Shah at: 6/23/2014 5:25:31 PM    

Hi Larry,
Good example for us, I must admit.
I noticed one thing:
I modify C2 value and press TAB, the total updates correctly.
However, when I "cancel changes" the total does not revert to the previous (unchanged) one.
Thought I'd let you know.
Best regards

Added By: Larry (DevExpress Support) at: 6/24/2014 7:52:35 AM    Hi Dhaval,

Thank you for your attention. I have modified the example. Added By: Dhaval.Shah at: 6/24/2014 7:51:38 PM    

Hi Larry,
Thanks for the prompt (as always) update, much appreciated.
It works. However, something's not right it appears:
Please try this.
Run the example, click on first row C2 column, type a number and press TAB.
I ran it in Chrome and the total was not updated (the value in cell reverted to the original value 0).
Then, I went back to the same cell, typed another number and pressed ENTER.
this time it updated correctly.
I must be doing something wrong, but thought I'd run it past you first.
Do update the thread when you can please.
Thanks.

Added By: Larry (DevExpress Support) at: 6/25/2014 3:09:00 AM    Thank you for the clarification. I have created a separate ticket on your behalf to process the issue more effectively:
ASPxGridView - Batch Editing - Some issues with the T114923 example
Please refer to it for further correspondence.              Added By: Alfredo Bergamo at: 11/10/2014 8:48:10 AM    

What happens if you add new rows or delete some of them? How I get the new sum?

Added By: Larry (DevExpress Support) at: 11/11/2014 4:15:19 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T171621: ASPxGridView - T114923 example: How to update total summaries when deleting or adding new rows. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Henry O at: 1/6/2016 11:15:26 AM    

Hello,

This solution works great, however, how do I get the total in the footer to format properly?  Specifically I need currency format.

Added By: Larry (DevExpress Support) at: 1/7/2016 2:57:58 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T331517: T114923 example - How to set the required format for the summay. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Viewing all 7205 articles
Browse latest View live


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