Conditional content

QuestionsConditional content
Fabio Martins asked 10 years ago

Hi,

Why the definition below doesn't work?

$col["condition"] = array('$row["deb"] = 0', '', $row["deb"]);

I want display nothing ('') if cell 'deb' is equal to 0 and display it when greater than 0.

Thank you!

16 Answers
Abu Ghufran answered 10 years ago

Instead of =, try ==

$col["condition"] = array('$row["deb"] == 0', '', $row["deb"]);

Fabio Martins answered 10 years ago

Now, it returns empty ('') in all cells (second parameter $row["deb"] doens't return nothing).
Thank you!

Abu Ghufran answered 10 years ago

The 2nd and 3rd argument are html content, in which you can use placeholder for col names.
$col["condition"] = array('$row["deb"] == 0', '', '{deb}');

Fabio Martins answered 10 years ago

Thank you!!! It works fine now!

Fabio Martins answered 10 years ago

Sir,

Please, the 3rd argument could to be a javascript function with colname parameter? For example: 'validateField({deb})'

Thank you!

Abu Ghufran answered 10 years ago

It can only be html code. You can use something like <a href='return void()' onclick='alert(2323)'>{deb}</a>.

Jesus Parra answered 10 years ago

I need help to integrate conditional content for extended options with callback functions

Abu Ghufran answered 10 years ago

Hello Jesus,

For conditional content, please refer demo/editing/conditional-data sample.
Please email me your scenario, what exactly are the options you are looking for.

Regards,

Jayashri Patil answered 10 years ago

Hi,

In condition can we add SQL QUERY like I want to check does that auto incremented ID exists in last three entries for that respective row's customer/user. Please let me know how can we do that.

I tried this but its giving me error in demo.

$col["condition"] = array('$row["id"] IN (SELECT id FROM invheader ORDER BY id desc limit 3)', 'DELETE','');

Hop this will clear you requirement, I want to give delete link to last three transactions of each customer

Please let me know as early as is it possible or not.

Thanks
Jayashri

Abu Ghufran answered 10 years ago

You can run this SQL and replace the result in condition.
for e.g.

$arr = array();
$q = mysql_query('SELECT id FROM invheader ORDER BY id desc limit 3');
while($rs =mysql_fetch_assoc($q))
{
$arr[] = $rs["id"];
}

$col["condition"] = array('$row["id"] == '.$arr[0].' || $row["id"] == '.$arr[1].' || $row["id"] == '.$arr[2], 'DELETE','');

Check for typos and this is not executed.

Jayashri Patil answered 10 years ago

Actually problem is we need client_id of each row

$col["condition"] = array('$row["id"] IN (SELECT id FROM invheader WHERE client_id=$row["client_id"] ORDER BY id desc limit 3)', 'DELETE','');

I want to give delete link to last three transactions of each client, so if client_id = 1 then give delete link to its latest 3 transactions only.

I think its not possible as mysql is giving error "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery"

Let me know if you have any idea to get the solution.

Thanks in advance

Abu Ghufran answered 10 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;
}
}

Navaneethan answered 9 years ago

Hi Abu,

$col["condition"] = array('$row["note"] == "No Bill"', "No Bill", "<a href='$upload_url/{note}'class='fancybox' data-fancybox-type='iframe'>Bill (Click Here)</a>");

in the above code it show column value equal to No Bill it display No bill otherwise it display Bill (Click Here) link.

Now i need another option to add "Need To Scan" in it how can i do this
Thanks,
P.Navaneethan

Navaneethan answered 9 years ago

Hi Abu,

$col["condition"] = array('$row["note"] == "No Bill"', "No Bill", "<a href='$upload_url/{note}'class='fancybox' data-fancybox-type='iframe'>Bill (Click Here)</a>");

in the above code it show column value equal to No Bill it display No bill otherwise it display Bill (Click Here) link.

Now i need another option to add "Need To Scan" in it how can i do this
Thanks,
P.Navaneethan

Navaneethan answered 9 years ago

Hi Abu,

$col["condition"] = array('$row["note"] == "No Bill"', "No Bill", "<a href='$upload_url/{note}'class='fancybox' data-fancybox-type='iframe'>Bill (Click Here)</a>");

in the above code it show column value equal to No Bill it display No bill otherwise it display Bill (Click Here) link.

Now i need another option to add "Need To Scan" in it how can i do this
Thanks,
P.Navaneethan

Abu Ghufran answered 9 years ago

Hi Navaneethan,

Refer docs for extended conditional content.

http://www.phpgrid.org/docs/#Conditional_Content

Basically you can call callback function to render the content.
$col["on_data_display"] = array("display_keyword","");

Your Answer

7 + 1 =

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?