Backgrid.SelectCell.extend option value must be a number?

86 Views Asked by At

Hy guys. How to convert option value of SelectCell from string to number using Backgrid.SelectCell.extend? I need list of years in select like [2019,2019], [2018,2018],[2017,2017].

1

There are 1 best solutions below

0
voric On

I find a solution. First create a new javascript variable (i named a SelectNumber)

`

var SelectNumber = Backgrid.SelectCell.extend({
  // any options specific to `select2` goes here
  selectOptions: {
    // default is false because Backgrid will save the cells value
    // and exit edit mode on enter
    openOnEnter: false
  },
  //optionValues: godine,
  // since the value obtained from the underlying `select` element will always be a string,
  // youll need to provide a `toRaw` formatting method to convert the string back to a
  // type suitable for your model, which is an integer in this case.
  formatter: _.extend({}, Backgrid.SelectFormatter.prototype, {
toRaw: function (formattedValue, model) {
    return parseInt(formattedValue);
  }
  })
});

` then add a nev variable '

var numbers=
[   
 [2019,2019],[2018,2018],[2017,2017],[2016,2016]
,[2015,2015],[2014,2014],[2013,2013],[2012,2012]
,[2011,2011],[2010,2010],[2009,2009]   
] ;

'

and add column to grid

' { name: "number", label: "number", cell: SelectNumber.extend({optionValues: numbers})

},'