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

How to define a column as a number in a particular range ?

Hi,

I have a ejs-grid that contains a column that is bound to a variable that is numeric.
When this column is in edit mode I'd like the user can't type characters different from digits (0-9) and also I'd like to specify at run-time a range among witch the typed number should stay (for example, say min 1 and max a variable set in the Vue.data).
I've tried a lot of examples in the documentation but I can't figure out how to achieve this.
I've used ":format="N"" to specify that the column is a number but the user still can type other chars.
I've provided a validationRules but I'm only able to specify that the column is required but I can't find in your examples a section that clearly esplains me all the possible validationRules I can attach to a column.
So I need an help from anyone, how to set a column as a number, required, and with min and max value set at runtime (not fixed with constants).

4 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team July 22, 2019 01:08 PM UTC

Hi Silvio, 

Greetings from Syncfusion support. 

We can achieve your requirement by setting the number column value as numeric edit type component to prevent to enter the other characters instead of numbers. We can set the min max values through the validation rules of columns API in Grid. 

Refer the below code example. 


<template> 
    <div id="app"> 
        <ejs-grid id="Grid" 
                  ref="grid" 
                  :dataSource="data" 
                  :editSettings="editSettings" 
                  :allowPaging="true" 
                  :toolbar="toolbar" 
                   
> 
            <e-columns> 
                <e-column field="OrderID" headerText="Order ID" isPrimaryKey="true" width="90"></e-column> 
                <e-column field="CustomerID" headerText="Customer ID" width="120"></e-column> 
                <e-column field="Freight" 
                          headerText="Freight" 
                          editType="numericedit" 
                          :validationRules="customerIDRules" 
                          type="number" 
                          width="90"></e-column> 
                <e-column field="ShipCountry" headerText="Ship Country" width="120"></e-column> 
            </e-columns> 
        </ejs-grid> 
    </div> 
</template> 
 
<script> 
import Vue from "vue"; 
import { GridPlugin, Page, Toolbar, Edit } from "@syncfusion/ej2-vue-grids"; 
import { DropDownListPlugin } from "@syncfusion/ej2-vue-dropdowns"; 
import { DropDownButtonPlugin } from "@syncfusion/ej2-vue-splitbuttons"; 
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons"; 
import { data } from "./datasource"; 
 
Vue.use(GridPlugin); 
Vue.use(ButtonPlugin); 
Vue.use(DropDownListPlugin); 
Vue.use(DropDownButtonPlugin); 
 
export default { 
  data() { 
    return { 
      waterMark: "Select a export option", 
      height: "220px", 
       
      data: data, 
      editSettings: { 
        allowEditing: true, 
        allowAdding: true, 
        allowDeleting: true 
      }, 
      toolbar: ["Add", "Edit", "Delete", "Update", "Cancel"], 
      customerIDRules: { required: true, min: 0, max: 1000 } 
    }; 
  }, 
  provide: { 
    grid: [Page, Toolbar, Edit] 
  }, 
  methods: {} 
}; 
</script> 

  
We have prepared a simple sample in the following link 


Refer the help documentation. 




Regards, 
Thavasianand S. 



SI Silvio July 22, 2019 07:07 PM UTC

Thank you!


RS Renjith Singh Rajendran Syncfusion Team July 24, 2019 01:01 PM UTC

Hi Silvio, 
  
We are happy to hear that your requirement has been achieved. 
  
Please get back to us if you need further assistance. 
  
Regards, 
Renjith Singh Rajendran. 



SI Silvio July 24, 2019 09:06 PM UTC

I have still another little question.
How is it possible to indicate that the bound variable is an integer variable and not a floating point one?
I'd like the user is able to type only digits (0-9) and not also the dot to have decimal values.

Loader.
Live Chat Icon For mobile
Up arrow icon