Ejs Grid with telephone mask

Good afternoon,

I'm trying to have a ejs grid with a mask for telephone numbers in a column like this "(555) 123 1234"


Can you help me please with this task?




5 Replies 1 reply marked as answer

PG Praveenkumar Gajendiran Syncfusion Team March 24, 2021 09:33 AM UTC

Hi Javier, 
 
Greetings from Syncfusion support. 
 
We checked your query. Based on that we suspect you want to mask/customise the Grid column content. For this we suggest you to use column.valueAccessor property which helps to achieve the custom value formatting in the Grid column content as demonstrated in the below code example. 


@{ 
    var valueAccessor = "valueAccessorFn"; 
} 
<ejs-grid id="Grid" dataSource="@ViewBag.datasource" height="500"> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" width="120"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer Name" width="120"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" format="C2" width="140"></e-grid-column> 
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column> 
        <e-grid-column field="Phonenumber" headerText="Phone Number" valueAccessor="valueAccessor" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
 
<script> 
    function valueAccessorFn(field, data1, column) { 
        if (data1[field]) { 
            return data1[field].replace(/^(\d{3})(\d{3})(\d{4}).*/, "($1) $2 $3"); 
        } 
    } 
</script> 
 

Screenshot: 

 

We have prepared a sample based on this for your reference,
 

For your reference, we have shared the column.valueAccessor documentation and we can access the field name, data of current row and current column details in this function. 



Note: While using valueAccessor in Grid’s column then the value is used for display purpose only which is default behavior of an EJ2 Grid. Customized column(using valueAccessor) value is not reflected in DB it update the HTML content alone. 

Please get back to us, if you need further assistance. 

Regards, 
Praveenkumar G 


Marked as answer

JA Javier A Aguilera March 25, 2021 11:26 PM UTC

Thats exactly what I was looking for!! thanks guys!!


PG Praveenkumar Gajendiran Syncfusion Team March 26, 2021 07:09 AM UTC

Hi Javier, 

You are welcome. We glad that the provided solution resolved your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Praveenkumar G 



DH David Heidlebaugh April 18, 2022 04:34 PM UTC

This has provide a solution to me too but when I edit the grid it puts the mask in.  I want it to have only what the table has in it



JC Joseph Christ Nithin Issack Syncfusion Team April 19, 2022 02:33 PM UTC

Hi David,


  Thanks for your update.


  Based on your query, you want to hide the masking when you edit the row. You requirement can be achieved by using the `actionComplete` event  of the EJ2 Grid. Where you can set the value from the datasource using the `args.rowData` property to the input element in the edit form .


Please refer the below code example.


 

function actionComplete(args) {

        if(args.requestType == "beginEdit") {

            args.form.querySelector('#GridPhonenumber').ej2_instances[0].value = args.rowData['Phonenumber'];

         }

    }

 


Please get back to us for further details.


Regards,

Joseph I.


Loader.
Up arrow icon