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

format string issue

hi,
i cannot find the solution for problem below.
if i have enter the valid format it still throw an error
format = ####.##.####.
allowTextWrap="false"
toolbar="@(new List() { "Add", "Edit", "Delete","ExcelExport"})"
toolbarClick="toolbarClick"
allowPaging="true"
allowSorting="true"
allowReordering="true"
allowSelection="true"
allowGrouping="false"
allowFiltering="true"
allowExcelExport="true"
showColumnMenu="true"
created="created"
allowResizing="true"
load="load"
actionBegin="actionBegin">
allowEditing="true"
allowDeleting="true"
mode="Dialog"
showDeleteConfirmDialog="true">
s
defaultValue="@ViewBag.Guid" showInColumnChooser="false">
defaultValue="@ViewBag.UserId">
isPrimaryKey="true" validationRules="@(new { required = false })"
template="#template3"
defaultValue="@ViewBag.Guid" allowEditing="false" showInColumnChooser="false" isIdentity="true">
}
function load() {
this.columns[0].validationRules = { required: true, length: [customFn, 'should be 12 number only'], format: [myFunction, 'follow the format ####.##.####'], number: [true, 'Required Numeric value'] };
//this.columns[0].format = { type: 'string', format: '####.##.####' };
this.columns[3].format = { type: 'date', format: 'dd/MM/yyyy' }; // set your customize date format based on your column
this.columns[3].validationRules = { required: true, minDate: [myFun1, 'Start Date must less than End Date'] };
this.columns[4].format = { type: 'date', format: 'dd/MM/yyyy' }; // set your customize date format based on your column
this.columns[4].validationRules = { required: true, minDate: [myFun2, 'End Date must greater than Start Date'] };
}
function myFun1(args) {
var entered = args.value.split("/");
var grid = document.getElementById("Grid").ej2_instances[0];
var endDate1 = document.getElementById(grid.element.id + grid.columns[4].field).value;
var enddatesplitted = endDate1.split("/");
if (new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= (new Date()).setHours(0, 0, 0, 0)) {
return new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) <= new Date(enddatesplitted[1] + '/' + enddatesplitted[0] + '/' + enddatesplitted[2]);
}
}
function myFun2(args) {
var entered = args.value.split("/");
var grid = document.getElementById("Grid").ej2_instances[0];
var startDate1 = document.getElementById(grid.element.id + grid.columns[3].field).value;
var startDateplitted = startDate1.split("/");
if (new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= (new Date()).setHours(0, 0, 0, 0)) {
return new Date(entered[1] + '/' + entered[0] + '/' + entered[2]) >= new Date(startDateplitted[1] + '/' + startDateplitted[0] + '/' + startDateplitted[2]);
}
}
function myFunction(args)
{
return args['value'].format == "9999.99.9999";
}
function customFn(args) {
return args['value'].length == 12;
}

5 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 3, 2019 11:35 AM UTC

Hi Siti,  

Greetings from Syncfusion.  

We could see the custom validation function for the format is not handled properly and you have simply checked its length which is the cause of the problem. We suggest to use the regex to check the required format within the custom function. Refer to the following code example.  

function myFunction(args) 
{ 
 return /\b\d{4}\.\d{2}\.\d{4}\b/.test(args['value']); 
} 
function load(args) { 
  this.columns[0].validationRules = { required: true, length: [customFn, 'should be 12 number only'], format: [myFunction, 'follow the format ####.##.####'] }; 
} 

  
Regards,  
Seeni Sakthi Kumar S 



SE Siti Emayati Murni Saddun Zuber October 4, 2019 09:52 AM UTC

Hai Seeni 
Tq for your respond.it's worked

regards
Ema


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 4, 2019 11:37 AM UTC

Hi Siti,  
  
We are happy to hear that your requirement has been achieved and you are good to go.

Please get back to us, if you require further assistance on this. 
  
Regards,  
Seeni Sakthi Kumar S 



GR Gowtham Raja June 30, 2022 07:57 AM UTC

hi syncfusion team ,

how about regex ? how to use it in for a cloumn

requirement is expect < and > symbol all other symbols are allowed



RR Rajapandi Ravi Syncfusion Team July 5, 2022 12:24 PM UTC

Hi Gowtham,


You can format the string as you want and display the value in the Grid column by using valueAccessor feature of Grid. The valueAccessor is used to access/manipulate the value of display data. You can achieve custom value formatting by using the valueAccessor. We have already discussed about your requirement in our documentation which can be accessed from the below link,


Documentation: https://ej2.syncfusion.com/aspnetcore/documentation/grid/columns/columns#valueaccessor


Note: The Value Accessor feature is used only for modifying the display data in UI level and it does not affect the grid’s data source. The Grid actions was performed based on the grid datasource.


Regards,

Rajapandi R


Loader.
Live Chat Icon For mobile
Up arrow icon