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. Image for the cookie policy date
close icon

GridNumericColumn restrict maximum number of characters allowed in EditMode

Hi,

Is there anyway I can restrict the maximum number of characters allowed to type in GridNumericColumn? I dont want user to type more than 5 characters in GridNumericColumn  column. Please let me know.

7 Replies

AN Ashok N Syncfusion Team April 14, 2015 06:38 PM UTC

Hi Diego,

Thank you for contacting Syncfusion support.

We have analyzed your query and you can achieve this, you need to deriveanew class fromtheGridCellNumericRenderer and overridetheOnInitializeEditElementmethod. Within this method you can the maximum length with help of SfNumericTextBox.MaxLength property. Please refer the below code example.

using Syncfusion.UI.Xaml.ScrollAxis;

using Syncfusion.UI.Xaml.Controls.Input;


public sealed partial class MainPage : Page

{

public MainPage()

{

this.InitializeComponent();

this.sfDataGrid.CellRenderers.Remove("Numeric");

this.sfDataGrid.CellRenderers.Add("Numeric", new GridCellNumericRendererExt());

}

}


public class GridCellNumericRendererExt : GridCellNumericRenderer

{

public override void OnInitializeEditElement(RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement, GridColumn column, object dataContext)

{

uiElement.MaxLength = 5;

base.OnInitializeEditElement(rowColumnIndex, uiElement, column, dataContext);

}

}

Also, you can achieve this by writing style to SfNumericTextBox and set value to MaxLength property within this style because we have load SfNumericTextBox in GridNumericColumn editing mode. Please refer the below code snippet.

xmlns:editors="using:Syncfusion.UI.Xaml.Controls.Input"

<Page.Resources>

<Style TargetType="editors:SfNumericTextBox">

<Setter Property="MaxLength" Value="5"/>

</Style>

</Page.Resources>

Please let us know if you require further assistance.

Thanks,

Ashok



VA Vasanth April 14, 2015 06:42 PM UTC

awesome, thanks!!


SC Saranya CJ Syncfusion Team April 15, 2015 05:50 AM UTC

Hi Diego,

Thank you for your update. Please let us know if you require any other assistance.

Regards,
Saranya


VA Vasanth April 22, 2015 04:41 PM UTC

Hi,
I am using GridCellNumericRendererExt class provided you by Ashok on 4/14 to set MaxLength. There is an issue with the custom renderer, it doesnt rollback to old value when user press esc key for validation issues.

If I dont use the custom renderer, and if validation fails for user input value then pressing esc key rollbacks value.


VA Vasanth April 22, 2015 04:58 PM UTC

One thing to note is, this only happens for indexed properties alone. 

Example: MappingName = "Customers[0].Expense"


VA Vasanth April 22, 2015 05:38 PM UTC

Never mind, I will create an incident for this issue.


AN Ashok N Syncfusion Team April 23, 2015 06:06 PM UTC

Hi Vasanth,

Thank you for your update.

We have analyzed your query and we are able to reproduce the reported “Esc Key does not reset the old value for indexer property when applying the validation” issue. We have updated the details in incident #138209, please refer this incident.

Please let us know if you require further assistance.

Thanks,
Ashok


Loader.
Live Chat Icon For mobile
Up arrow icon