Author Topic: Restrict cell data upto certain characters  (Read 2423 times)

cijojohn

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 73
    • View Profile
Restrict cell data upto certain characters
« on: January 29, 2018, 03:14:52 pm »
Hi Team,

we need to set the column data as per the max chars allowed for column.e.g i have column A which has value more than 40 characters. But on grid i always want to show/save/copy/paste(all actions) upto maximum 30 characters.

Please refrer attached snap. Column A has values more than 20 characters(which is present in the grid Data coming from service). Now, we want this should only accept upto 20 characters and ignore the remaining.

We have added the validation for the cell, it is working upon editing. But on copy paste,grid population with data from service it still accepts.




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: Restrict cell data upto certain characters
« Reply #1 on: January 29, 2018, 04:24:39 pm »
There is a difference between disallowing invalid values and processing data to make it acceptable.

Disallow invalid values:

Use validations.
1. Set editModel.allowInvalid = false to disallow invalid values in cells while editing.
2. Set pasteModel.allowInvalid = false to disallow invalid values in cells while copy/paste.

Data processing:

For data loading from external data source, data could be processed manually by iterating through the rows.

Code: [Select]
data.forEach(function(rowData){
  if(rowData[dataIndx].length > n)
    rowData[dataIndx] = rowData[dataIndx].substring(0, n)
})

For all other actions, beforeValidate event can be used to process the data.

Code: [Select]
beforeValidate: function(evt, ui){
ui.updateList.forEach(function(obj){
  var newRow = obj.newRow;
  if(newRow[dataIndx].length > n)
    newRow[dataIndx] = newRow[dataIndx].substring(0, n)
})
ui.addList.forEach(function(obj){
  var newRow = obj.newRow;
  if(newRow[dataIndx].length > n)
    newRow[dataIndx] = newRow[dataIndx].substring(0, n)
}) 
}
« Last Edit: January 29, 2018, 04:28:17 pm by paramquery »

cijojohn

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 73
    • View Profile
Re: Restrict cell data upto certain characters
« Reply #2 on: January 29, 2018, 05:40:01 pm »
Thanks its working  :)