Conditional Buttons

QuestionsConditional Buttons
Ananda Theerthan asked 6 years ago

Hi,

$col = array();
$col["title"] = "Options";
$col["name"] = "more_options";
$col["width"] = "30";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
# no new line in this html, only space. otherwise it may break ui of grid
$buttons_html = "<a target='_blank' href='1.php?id={id}' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:red'>Button1</a> <a target='_blank' href='2.php?sid={id}' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:green'>Button2</a>";
$col["default"] = $buttons_html;
$cols[] = $col;

I use above code for displaying buttons every row. Can I make it to display conditionally? For ex, if col1 = 10, only then display the buttons?

3 Answers
Abu Ghufran answered 6 years ago

For extended conditional data, you can also have callback function, that will allow you to display based on row data. For e.g.

$col["on_data_display"] = array("display_keyword","");

function display_keyword($data)
{
$kw = $data["keyword_name"];
$numKeywords = count(explode("n",$pass));
if ($numKeywords > 3)
return $numKeywords." Keywords";
else
{
$pass = str_replace("+"," ",$pass);
return $pass;
}
}

Ananda Theerthan answered 6 years ago

Thanks,
But I want to display first button always but conditionally display the second button? Do I need to use separate column for this or is there a solution?

Abu Ghufran answered 6 years ago

Alternate column is not necessary.

Code would be something like: http://pastebin.com/DjNjMEgh

Your Answer

10 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?