Get Free Trial

Disable/enable cell click

Anusha A asked on March 25, 2021

I have a scenario where we will check if the image exists or not before the cell click event. 

if an image exists we will enable the cell to perform a cell click event.

if not we have to disable the cell click to prevent events in react js.

to check the image we are calling external API.

please help me to achieve the results. 

3 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 26, 2021

Thank you for reaching out to us.
As for now, for us, the scenario looks similar to the following:

  1. The user clicks on the cell.
  2. External API checks if the image exists.
  3. If the image exists, execute the handler of the cellclick event. If the image does not exist, ignore the handler of the cellclick event.

If our assumption is correct, please see the following suggestion:
You can perform an image check inside the cellclick handler and continue execution if the image exists. Otherwise, interrupt the execution by returning from the handler function.
We have prepared the JSFiddle to demonstrate this approach: It uses the mock function that replaces an external API and answers with a boolean depending on whether the “image” exists:

flexmonster.on("cellclick", cellClickHandler); //subscription to the event

function cellClickHandler(cell) {
  if (!checkImage()) return; //check if image exists. If not, return from the function
  alert("Handler executed"); //handler itself

function checkImage() { //mock function
  return Math.random() > 0.5;

Please let us know if it helps.
If we did not understand you correctly, please provide us with additional details about the required functionality. It would be useful to receive a detailed scenario/step-by-step explanation.
We are looking forward to hearing from you.
Kind regards,

Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 31, 2021

We are reaching out to ask if the provided solution works for you.
Our team is looking forward to hearing your feedback.


Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 7, 2021

We are curious if you had some time to check out the proposed solution.
Please let us know if any questions appear on this point.
Kind regards,

Please login or Register to Submit Answer