Continuing the discussion from Custom renderer not detecting NULL:
Hey @aleksandra_budnik !
It’s been a while I haven’t had the time to update or complete the project so far, so here is an update. My issue is that my renderer and my functions work in-sync as long as the user saves the data to render the like, but if they type in a value and like it and end up refreshing without saving the value, the renderer still updates the database.
Basically, the user inputs a data into the resolution column and immediately the “Like button” renders next to it because there is data in it. The next immediate protocol is to save the data, but if the user instead refreshes (assuming they are high IQ geniuses), the heart icon is still updated in the data base but the value is gone because it is temporary and not saved. I am handling both the “Like button” and the value appropriately but unable to find a way out, let me know if I am doing something wrong, here is the code:
hot = new Handsontable(container, {
licenseKey: 'non-commercial-and-evaluation',
data: data,
{% if(window.width() >= 1350) %}
height: $(window).height(),
width: $(window).width()-220,
{% else %}
width: $(window).width()-12,
height: $(window).height()-180,
{% endif %}
manualRowResize: true,
rowHeaders: true,
rowHeights: 50,
className: 'htMiddle',
renderer: detailRenderer,
fillHandle: false,
preventScrolling: false,
hiddenColumns: {columns: [0,9,10,11,12, 13, 14, 15]},
filters: true,
dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'],
columns: [
{data:'KEY', title:'', width:50, readOnly:true},
{% if systemUser == 1 %}
{data:'RANK', title:'RANK', width:70, type:'dropdown', source:[' ','🥇','🥈','🥉']},
{% else %}
{data:'RANK', title:'RANK', width:70, readOnly:true},
{% endif %}
{data:'USRID', title:'USRID', className: 'htCenter htMiddle', readOnly:true, width:100},
{data:'USRNM', title:USRNM', width:145, readOnly:true},
{data:'AFFILIATION', title:'AFFILIATION', width:253, readOnly:true},
{data:'GOAL_COMMIT', title:'GOAL_COMMIT', width:325, readOnly:true},
{data:'REPLY_COMMENT', title:'REPLY_COMMENT', width:325, readOnly:true},
{data:'RESULT', title:'RESULT', width:70, readOnly:true, source: [' ','⭕', '✖️']},
{data:'GOAL_COMMENT', title:'GOAL_COMMENT', width:325, readOnly:true},
{data:'GOAL_COMMIT_LIKES'},
{data:'REPLY_COMMENT_LIKES'},
{data:'GOAL_COMMENT_LIKES'},
{data: 'USRCD'},
{data: 'GOAL1'},
{data: 'GOAL2'},
{data: 'GOAL3'},
],
afterChange: getChangedRows,
afterGetRowHeader: function(col, TH) {
TH.className = 'htMiddle'
},
cells: function (row, col) {
var cellProperties = {};
cellProperties.renderer = detailRenderer;
return cellProperties;
}
});
My getChangedRows:
> function getChangedRows(changes) {
> if(changes == null) {
> return;
> }
> changes.forEach(([row, prop, oldValue, newValue]) => {
> //console.log(oldValue, newValue);
> if(oldValue != newValue){
> let ID = hot.getDataAtRowProp(row,"USRNM");
> changeList.push(ID);
> if(newValue==null || newValue=="") {
> deleteFlag = 1;
> //get the value at the cell that was changed
> var cellValue = hot.getDataAtRowProp(row, prop);
> // get the value at the heart icon cell
> var gCommitHeartValue = hot.getDataAtRowProp(row, "GOAL_COMMIT_LIKES");
> gCommitHeartValue = 0;
> var rCommentHeartValue = hot.getDataAtRowProp(row, "REPLY_COMMENT_LIKES");
> rCommentHeartValue = 0;
> var gCommentHeartValue = hot.getDataAtRowProp(row, "GOAL_COMMENT_LIKES");
> gCommentHeartValue = 0;
> }
> if(oldValue== "" || oldValue==null) {
> //get the value at the cell that was changed
> var cellValue = hot.getDataAtRowProp(row, prop);
> // get the value at the heart icon cell
> console.log("oldValue is null");
> deleteFlag = 1;
> if(oldValue != newValue) {
> if(prop == "GOAL_COMMIT") {
> var gCommitHeartValue = hot.getDataAtRowProp(row, "GOAL_COMMIT_LIKES");
> gCommitHeartValue = 0;
> console.log("gCommitHeartValue: " + gCommitHeartValue);
> }
> else if(prop == "REPLY_COMMENT") {
> var rCommentHeartValue = hot.getDataAtRowProp(row, "REPLY_COMMENT_LIKES");
> rCommentHeartValue = 0;
> console.log("rCommentHeartValue: " + rCommentHeartValue);
> }
> else if(prop == "GOAL_COMMENT") {
> var gCommentHeartValue = hot.getDataAtRowProp(row, "GOAL_COMMENT_LIKES");
> gCommentHeartValue = 0;
> console.log("gCommentHeartValue: " + gCommentHeartValue);
> }
> }
> }
> }
> //get the column number
> var col = hot.propToCol(prop);
> if(col == 5 || col == 6 || col == 8 || col == 9 || col == 10 || col == 11 || col == 13 || col == 14 || col == 15) {
> if(col == 5) {
> likesid = 1;
> }
> else if (col == 6) {
> likesid = 2;
> }
> else if (col == 8) {
> likesid = 3;
> }
> var row = hot.getSelected()[0];
> //get the data before editing
> var oldData = hot.getSourceDataAtRow(row);
> console.log(oldData);
> //get the data after editing
> var rowData = hot.getDataAtRow(row);
> console.log(rowData);
> if(oldData != rowData) {
> var param = {
> 'challengeID': challengeID,
> 'userID': userID,
> 'likesid': 0,
> 'deleteFlag': deleteFlag
> };
> }else {
> var param = {
> 'challengeID': challengeID,
> 'userID': userID, // 投稿がいいね! されたユーザーの ID - id of the user whose post is liked
> 'likesid': likesid,
> 'deleteFlag': deleteFlag
> };
> }
> var userID = hot.getDataAtRowProp(row, "SYACD");
> var challengeID= $("#title").data('challengeid');
> //console.log(param);
> var url = 'like_delete';
> $.ajax({
> url: url,
> type: 'GET',
> data: param
> });
> }
> });
> }
My renderer:
function detailRenderer(instance, td, row, col, prop, value, cellProperties) {
if (col == 5) {
if (value != null && instance.getDataAtCell(row, 9) != 0){
if(value !='' && instance.getDataAtCell(row, 13)!= 0) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="goalLikes" id="goalLikesButton'+row+'" class="fas fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 9) + '</div></div>';
}
else if(instance.getDataAtCell(row, 13)== 0){
if(value !=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="goalLikes" id="goalLikesButton'+row+'" class="far fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 9) + '</div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else if(value != null && instance.getDataAtCell(row, 9) == 0){
if(value!=''){
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value+'<div class="in-like" style="color:red; text-align:center;"><i data-type="goalLikes" id="goalLikesButton" class="far fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row,12)+'" onclick="likesFunction(this)" ></i></div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else{
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else if (col == 6) {
if (value != null && instance.getDataAtCell(row, 10) != 0){
if(value !='' && instance.getDataAtCell(row, 14)!= 0) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="replyLikes" id="replyLikesButton'+row+'" class="fas fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 10) + '</div></div>';
}
else if(instance.getDataAtCell(row, 14)== 0){
if(value !=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="replyLikes" id="replyLikesButton'+row+'" class="far fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 10) + '</div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else if(value != null && instance.getDataAtCell(row, 10) == 0){
if(value!=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value+'<div class="in-like" style="color:red; text-align:center;"><i data-type="replyLikes" id="replyLikesButton'+row+'" class="far fa-heart" data-id="replyLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row,12)+'" onclick="likesFunction(this)" ></i></div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else{
if(value!=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
}
}
}
else if (col == 8) {
if (value != null && instance.getDataAtCell(row, 11) != 0){
if(value !='' && instance.getDataAtCell(row, 15)!= 0) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="resultLikes" id="resultLikesButton'+row+'" class="fas fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 11) + '</div></div>';
}
else if(instance.getDataAtCell(row, 15)== 0){
if(value !=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value + '<div class="in-like" style="color:red; text-align:center;"><i data-type="resultLikes" id="resultLikesButton'+row+'" class="far fa-heart" data-id="goalLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row, 12)+'" onclick="likesFunction(this)"></i>' + instance.getDataAtCell(row, 11) + '</div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else if(value != null && instance.getDataAtCell(row, 11) == 0){
if(value!=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.innerHTML = '<div class="like">'+value+'<div class="in-like" style="color:red; text-align:center;"><i data-type="resultLikes" id="resultLikesButton'+row+'" class="far fa-heart" data-id="resultLikesButton'+row+'" data-userid="'+instance.getDataAtCell(row,12)+'" onclick="likesFunction(this)" ></i></div></div>';
}
else {
Handsontable.renderers.HtmlRenderer.apply(this, arguments);
}
}
else{
if(value!=''){
Handsontable.renderers.TextRenderer.apply(this, arguments);
}
}
}
else{
Handsontable.renderers.TextRenderer.apply(this, arguments);
}
}
I have put this here since the other custom renderer issue was closed, apologies if it is unrelated.
Any help in understanding what I am doing wrong is appreciated.
Thanks!