I think I'm a bit confused on how to implement my cell editor as I'm testing out AG Grid. I have a field called "Week1" with a value of "a:8:0.63:0:1:0:1".
I'm using a cellRenderer to split that and use the second element as a number of hours to display along with some cell coloring based on the other values. I'm returning html like '<div class="' + bg + '">' + hrs + '</div>'.
That all looks great. But now I'm trying to apply an "agNumberCellEditor" editor. When it goes into edit mode it has a blank value so I don't understand how/when/where to set that value from the second value of my split.
When I type in another value I'm returning it via a valueParser which combines the string back onto the colon separated string. If I type a "5" I'm returning "a:5:0.63:0:1:0:1" but that just throws an error as it re-calls the renderer which now has a blank value.
Am I missing something or just plain doing it wrong? I already gave up on a custom editor as the documentation is lacking, especially for Vue. I did try using a valueGetter which allowed the number to come through to the editor but wiped out all my rendering. Any clue(s) would be appreciated.
Renderer:
const hourCellRenderer = (params) => {
const parts = params.value.split(':')
let hrs = parts[1]
const val = parseFloat(parts[2])
const vacDays = parts[3]
const isWeekEmployed = parts[4]
const isOnLeave = parts[5]
let bg = val >= 1 ? 'cap-gt-115' : val >= 0.79 ? 'cap-80-115' : 'cap-lt-80'
bg += parseInt(isWeekEmployed)
? (parts[0] === 'a')
? ' actual'
: ' future'
: ' notEmployed'
if (parseInt(hrs) === 0 && parts[0] === 'f') { hrs = ' ' } // no hours is blank
if (!parseInt(isWeekEmployed)) { hrs = ' ' } // not employed is blank
if (vacDays === '1') { bg += ' cap-vac-1' } // vacation gradients
if (vacDays === '2') { bg += ' cap-vac-2' }
if (vacDays === '3') { bg += ' cap-vac-3' }
if (vacDays === '4') { bg += ' cap-vac-4' }
if (vacDays === '5') { bg += ' cap-vac-5' }
if (parseInt(isOnLeave) === 1) { bg += ' onLeave' } // on leave is blue
return '<div class="' + bg + '">' + hrs + '</div>'
}
valueParser:
const HoursParser = (params) => {
const val = parseInt(params.newValue)
const oldValues = params.oldValue.split(':')
oldValues[1] = val + ''
return oldValues.join(':')
}