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

How to to show Top N Values calculated by a certain measure using the Context Menu

$
0
0
To accomplish this task, it is necessary to enable the Sorting by Summary and Top N Values features simultaneously. To add a custom context menu item, handle the PivotGridControl.PopupMenuShowing event. Please refer to the attached sample project demonstrating this approach. 
Question Comments

Added By: Vijay Sagar 1 at: 2/28/2018 6:56:35 AM    This example does not work properly.  When I try to right-click on a cell, I get an error.
Also in the code, I am getting "FieldValueCellElement is obsolete" message . It says it has been deprecated.

ASPxGridView - How to create a header's button that allows ungrouping a column on a click

$
0
0

This example demonstrates how to create a button inside the grid's header that allows ungrouping a column by a click.

We will use the HeaderCaption Template to add the UnGroup button to the column's header:


[C#]
classMyTemplate:ITemplate{publicvoidInstantiateIn(Controlcontainer){GridViewHeaderTemplateContainergridContainer=(GridViewHeaderTemplateContainer)container;stringfieldName=(gridContainer.ColumnasGridViewDataColumn).FieldName;Literalcaption=newLiteral();caption.ID="caption_"+gridContainer.ItemIndex.ToString();caption.Text=fieldName;container.Controls.Add(caption);ASPxImageimage=newASPxImage();image.ID="unGroup_"+gridContainer.ItemIndex.ToString();image.ImageUrl="~/Delete.png";image.ToolTip="UnGroup column";container.Controls.Add(image);image.ClientSideEvents.Click=string.Format("function(s, e){{ gridView.UnGroup ('{0}'); }}",fieldName);image.ClientSideEvents.Init="OnImageInit";}}

The OnImageInit function prevents the grid's sorting when a user clicks the UnGroup button:

[JavaScript]
function OnImageInit(s, e){var element = s.GetMainElement(); element.onmousedown = element.onmouseup = function(event){ event.cancelBubble = true;returnfalse;};}

However, it is necessary to set a template only for grouped columns. For this, use the following code:

[C#]
protectedvoidCreateUnGroupButton(){foreach(GridViewDataColumncolumninGridView1.DataColumns){if(column.GroupIndex!=-1){column.HeaderCaptionTemplate=newMyTemplate();}}}

ASPxGridView - Master-detail - How to hide rows that do not have any details

$
0
0

This example illustrates how to show only grid rows that have detail data. If the row detail grid is empty, that row should be hidden.

ASPxGridView - How to create HyperLink Column whose URL depends on several column values

$
0
0
This example demonstrates how to create GridViewDataHyperLinkColumn whose URL depends on several column values. Instead of creating a custom DataItemTemplate (How to use a hyperlink whose argument depends on several cell values in the ASPxGridView), you can use Unbound Column.  
Create a column's URL using the GridViewDataColumn.UnboundExpression property:
[ASPx]
<dx:GridViewDataHyperLinkColumnFieldName="HyperLinkColumn"UnboundType="String"UnboundExpression="'Default2.aspx?id='+[CategoryID]+'&name='+[CategoryName]"VisibleIndex="4"><PropertiesHyperLinkEditTextField="CategoryName"DisplayFormatString="Open <b>{0}<b/>"></PropertiesHyperLinkEdit></dx:GridViewDataHyperLinkColumn>
or use the HyperLinkProperties.NavigateUrlFormatString property to add extra text to the complete URL:
[ASPx]
<dx:GridViewDataHyperLinkColumnFieldName="HyperLinkColumn2"UnboundType="String"UnboundExpression="'?id='+[CategoryID]+'&name='+[CategoryName]"VisibleIndex="4"><PropertiesHyperLinkEditTextField="CategoryName"DisplayFormatString="Open <b>{0}<b/>"NavigateUrlFormatString="Default2.aspx{0}"></PropertiesHyperLinkEdit></dx:GridViewDataHyperLinkColumn>

Using this approach, you will be able to preserve the full GridViewDataHyperLinkColumn functionality. 

ASPxGridView - How to copy an alternative row style to the preview row for a grouped grid

$
0
0

For this task, handle the ASPxGridView.HtmlRowPrepared event to add the required CSS class for the alternating preview rows:

[C#]
boolisPrevRowIsAlterRow;protectedvoidgrid_HtmlRowPrepared(objectsender,DevExpress.Web.ASPxGridViewTableRowEventArgse){if(e.RowType==GridViewRowType.Data){isPrevRowIsAlterRow=e.Row.CssClass.Contains("dxgvDataRowAlt");}elseif(e.RowType==GridViewRowType.Preview){if(isPrevRowIsAlterRow)e.Row.CssClass+=" previewRowAlt";}}

ASPxGridView - Batch Edit - How to change the MaxLength property based on the key value

$
0
0

This example illustrates how to change an editor's server-side properties based on the key value if ASPxGridView uses the Batch Edit mode. ASPxMemo placed inside the C3 column has different MaxLength for different rows: MaxLength = 4 for rows with the odd ID and 10 for rows with the even ID. 

Note: this example is created based on the ASPxGridView - Batch Editing - A simple implementation of an EditItem template one. You can refer to this example to get information about the implementation of the ASPxGridView's EditItem template in BatchEdit mode.  

ASPxGridView - How to use a different PopupEditForm caption for row editing and inserting

$
0
0

This example demonstrates how to set a different Popup EditForm caption when editing and inserting a new row.

How to define global settings for all project controls without creating a custom theme


dxDataGrid - Batch Editing - How to select several cells for editing using the CTRL key

$
0
0

This example illustrates how to allow end used to select more than one cell for editing by holding the CTRL key. Then, when the user changes the editor text, the same text will be entered to all selected cells. 

It is possible to implement this scenario by performing the following steps:

Create an array to store selected cells:

[JavaScript]
var editCells = [];

 Then, handle the onCellClick event to add the selected cell to the array when the Ctrl key is held or clear the array if it is not:

[JavaScript]
onCellClick: function(e){if(e.jQueryEvent.ctrlKey){ editCells.push(e.rowIndex + ":" + e.columnIndex);}elseif(editCells.length){ editCells = []; e.component.repaint();}},

 The onCellPrepared event is handled to change the style of the selected row: 

[JavaScript]
onCellPrepared: function(e){if(e.rowType === "data"&& $.inArray(e.rowIndex + ":" + e.columnIndex, editCells)>= 0){ e.cellElement.css("background-color", "lightblue");}},

 After that, handle the onEditorPreparing event to set the text value for all selected cells when a user edits the last cell:

[JavaScript]
onEditorPreparing: function(e){var grid = e.component;if(e.parentType === "dataRow"){var oldOnValueChanged = e.editorOptions.onValueChanged; e.editorOptions.onValueChanged = function(e){ oldOnValueChanged.apply(this, arguments);for(var i = 0; i < editCells.length; i++){var rowIndex = Number(editCells[i].split(":")[0]);var columnIndex = Number(editCells[i].split(":")[1]); grid.cellValue(rowIndex, columnIndex, e.value);}}}},

 To reset the selection when the Save or Cancel button is clicked, use the onContentReady event:

[JavaScript]
onContentReady: function(e){ e.element.find(".dx-datagrid-save-button").click(function(e){if(editCells.length) editCells = [];}); e.element.find(".dx-datagrid-cancel-button ").click(function(e){if(editCells.length) editCells = [];});}

ASPxGridView - How to sae a focused row index to cookies on the server side

$
0
0

The ASPxGridView does not save a focused row in cookies. However, you can add this capability by saving and restoring a focused row index to/from the cookies manually. If the ProcessFocusedRowChangedOnServer property is "true", changing of the focused row is processed on the server side. Thus, it is necessary to save and restore the focused index on the server side:

[C#]
protectedvoidgridView_FocusedRowChanged(objectsender,EventArgse){ASPxGridViewgrid=senderasASPxGridView;Response.Cookies[grid.ID]["FocudedIndex"]=grid.FocusedRowIndex.ToString();Response.Cookies[grid.ID].Expires=DateTime.Now.AddDays(1d);}protectedvoidgridView_DataBound(objectsender,EventArgse){ASPxGridViewgrid=senderasASPxGridView;if(!IsPostBack)if(Request.Cookies[grid.ID]!=null)grid.FocusedRowIndex=Convert.ToInt32(Request.Cookies[grid.ID]["FocudedIndex"]);}

SeeAlso:
ASPxGridView - How to store a focused row index in cookies

ASPxGridView - Batch Editing - How to update summaries when HighlightDeletedRows=true

$
0
0

ASPxGridView - How to show the live data without refreshing the grid (using WebMethods)

$
0
0

This example demonstrates how to update data only for several (or all, if it is required) grid columns without refreshing the entire grid. The main idea is to create a custom DataItem template for the required columns and then update its data on the client side. The server-side values can be obtained without the grid callback by using WebMethods

See Implementation Details for more information. 

See also:
How to display dynamic data within the ASPxGridView (Live Data) without full grid updating using the ASPxCallback control

ASPxRadioButtonList - How to show both text and value in the bound editor items

$
0
0

This example demonstrates how to show a text and value in items when the ASPxRadioButtonList is bound to a database.

ASPxGridView - How to specify HeaderCaptionTemplate and prevent the default mouse actions

$
0
0

This example demonstrates how to define some control inside a header caption template and prevent a default action for the specified events.

1) Define any control in GridViewColumn.HeaderCaptionTemplate and wrap it with a div tag/container;
2) Handle the div client-side onmousedown and onmouseup events and prevent the default action (column sorting) via the client-side ASPxClientUtils.PreventEventAndBubble method.

GridView - Batch Editing - How to display save and cancel buttons only after editing


ASPxGridView - How to turn off sorting for the Customization Window columns

$
0
0

This example illustrates how to turn off sorting for columns that are placed in the Customization Window, i.e. for hidden columns. 

GridView - How to automatically resize the grid to 100% inside a resizable PopupControl

$
0
0

This example illustrates how to set the grid's width and height to 100% when it is placed inside a resizable container. The How to use the GridView extension in a Full Screen mode (100% browser Width and Height) example describes how to accomplish this task when the grid is paced into the page directly. If the grid is placed inside some container, it is necessary to handle container resizing to set the grid height:

[C#]
settings.ClientSideEvents.AfterResizing="function(s, e){ GridView.SetHeight(document.getElementById('containerDiv').clientHeight); }";

 GridView is placed inside the div element with height and width equal to 100% to get the client height of the container's content area:

[C#]
ViewContext.Writer.Write("<div id='containerDiv' style='height:100%; widht:100%'>");Html.RenderAction("GridViewPartial");ViewContext.Writer.Write("</div>");

ASPxGridView - How to filter a column via ASPxTokenBox with changing the filter operator

How to use GetMainElement/GetInputElement to change control styles on the client side

ASPxGridView - How to set a different color for the modified cell in Batch Edit mode

$
0
0

Starting with version 16.1, this scenario is supported out of the box with the column's BatchEditModifiedCellStyle property:

[ASPx]
<dx:GridViewDataSpinEditColumnFieldName="C2"><BatchEditModifiedCellStyleBackColor="LightCoral"></BatchEditModifiedCellStyle></dx:GridViewDataSpinEditColumn><dx:GridViewDataTextColumnFieldName="C3"><BatchEditModifiedCellStyleBackColor="LightYellow"></BatchEditModifiedCellStyle></dx:GridViewDataTextColumn>
Question Comments

Added By: Yahya Ali at: 4/29/2014 7:52:33 AM    

impressive! but needs some documentations to get the full idea.

Added By: Larry (DevExpress Support) at: 4/30/2014 3:55:26 AM    Hello,

I have created a separate ticket on your behalf to process your inquiry more effectively:

Documentation for the E5140 example

Please refer to it for further correspondence.

Viewing all 7205 articles
Browse latest View live


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