hidegrid question

Questionshidegrid question
Carolyn asked 10 years ago

I have a grid that is not always populated with records. Following is what I have. However, the problem is that I DO NOT want the grid to display if $num_rows = 0. For some reason the following code is never hiding the grid.

any insight would be greatly appreciated.

$g->set_options($grid);

//hide grid
$grid["hidegrid"] = true;

$g->set_options($grid);
$g->set_actions(array(
"add"=>false, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance))
);

// you can provide custom SQL query to display data
$g->select_command = "SELECT tbl_DR.dr_id, tbl_DR.reference_number, tbl_DR.inspection_date, 5 * (DATEDIFF(now(), tbl_DR.inspection_date) DIV 7) + MID('0123444401233334012222340111123400001234000123440', 7 * WEEKDAY(tbl_DR.inspection_date) + WEEKDAY(now()) + 1, 1) as days,tbl_DR.inspector_id, tbl_DR.building_type_id, tbl_DR.building_permit_number, tbl_DR.Inspection_Num, tbl_DR.certificate_num, tbl_DR.owner_name, tbl_DR.owner_street_number, tbl_DR.owner_street, tbl_DR.owner_aptunit, tbl_DR.owner_address, tbl_DR.owner_city_id, tbl_DR.owner_state_id, tbl_DR.owner_county_id, tbl_DR.owner_phone, tbl_DR.owner_email, tbl_DR.owner_fax, tbl_DR.owner_zip, tbl_DR.owner_communication_method_id, tbl_DR.electrical_company_id, tbl_DR.ele_not_in_list, tbl_DR.service_number, tbl_DR.service_provider_id, tbl_DR.m_cert, tbl_DR.Inspection_HOCertificate, tbl_DR.e_cert, tbl_DR.Inspection_CutinCardCert, tbl_DR.Inspection_HOInvoice, tbl_DR.e_invoice, tbl_DR.code_ref, tbl_DR.job_total, tbl_DR.is_active, tbl_DR.user_id, tbl_DR.mail_address, tbl_DR.dt_added, tbl_DR.equipment, tbl_DR.notes, tbl_DR.request_type, tbl_DR.request_dt, tbl_DR.final_type, tbl_DR.final_dt, tbl_DR.final_inspector, tbl_DR.failed, tbl_DR.failed_dt, tbl_DR.failed_inspector FROM tbl_DR LEFT JOIN tbl_inspection ON tbl_DR.Inspection_Num = tbl_inspection.Inspection_Num WHERE (((tbl_inspection.Inspection_Num) Is Null)) and 5 * (DATEDIFF(now(), tbl_DR.inspection_date) DIV 7) + MID('0123444401233334012222340111123400001234000123440', 7 * WEEKDAY(tbl_DR.inspection_date) + WEEKDAY(now()) + 1, 1) >10 and ((tbl_DR.inspector_id)='$user_id') ";

function pre_render($data)
{
// same sql as in select_command
$result = "SELECT tbl_DR.dr_id, tbl_DR.reference_number, tbl_DR.inspection_date, 5 * (DATEDIFF(now(), tbl_DR.inspection_date) DIV 7) + MID('0123444401233334012222340111123400001234000123440', 7 * WEEKDAY(tbl_DR.inspection_date) + WEEKDAY(now()) + 1, 1) as days,tbl_DR.inspector_id, tbl_DR.building_type_id, tbl_DR.building_permit_number, tbl_DR.Inspection_Num, tbl_DR.certificate_num, tbl_DR.owner_name, tbl_DR.owner_street_number, tbl_DR.owner_street, tbl_DR.owner_aptunit, tbl_DR.owner_address, tbl_DR.owner_city_id, tbl_DR.owner_state_id, tbl_DR.owner_county_id, tbl_DR.owner_phone, tbl_DR.owner_email, tbl_DR.owner_fax, tbl_DR.owner_zip, tbl_DR.owner_communication_method_id, tbl_DR.electrical_company_id, tbl_DR.ele_not_in_list, tbl_DR.service_number, tbl_DR.service_provider_id, tbl_DR.m_cert, tbl_DR.Inspection_HOCertificate, tbl_DR.e_cert, tbl_DR.Inspection_CutinCardCert, tbl_DR.Inspection_HOInvoice, tbl_DR.e_invoice, tbl_DR.code_ref, tbl_DR.job_total, tbl_DR.is_active, tbl_DR.user_id, tbl_DR.mail_address, tbl_DR.dt_added, tbl_DR.equipment, tbl_DR.notes, tbl_DR.request_type, tbl_DR.request_dt, tbl_DR.final_type, tbl_DR.final_dt, tbl_DR.final_inspector, tbl_DR.failed, tbl_DR.failed_dt, tbl_DR.failed_inspector FROM tbl_DR LEFT JOIN tbl_inspection ON tbl_DR.Inspection_Num = tbl_inspection.Inspection_Num WHERE (((tbl_inspection.Inspection_Num) Is Null)) and 5 * (DATEDIFF(now(), tbl_DR.inspection_date) DIV 7) + MID('0123444401233334012222340111123400001234000123440', 7 * WEEKDAY(tbl_DR.inspection_date) + WEEKDAY(now()) + 1, 1) >10 and ((tbl_DR.inspector_id)='$user_id') ";
$num_rows = mysql_num_rows($result);
}

$grid_id = "list1";
// generate grid output, with unique grid name as 'list1'
$out = $g->render("list1");
?>

<?php
include("logincheck.php");

$TITLE = "Inspection Search";
include("head1.php");

include("nav2.php");
?>
<script>

$(window).load( function () {
if (!empty($user_id))
{
$_SESSION['user_id'] = $user_id;
}
$user_id = $_SESSION['user_id'];
if($num_rows !=0)
{
$grid["hidegrid"] = false;

}

});
});

</script>

1 Answers
Abu Ghufran answered 10 years ago

Please check following issues in your code:

1) The variable $num_rows is filled inside function so this variable is local to the function and will not the accessible outside it. Better declare it global to access it outside.
2) The hidegrid param that is later set at end of code, will never work as it is not passed to function $g->set_options($grid);

My recommendation is to make the num_rows as global and based on it's value, put the grid display (echo $out) on it's conditional value. Don't use hidegrid option for it.

Your Answer

9 + 0 =

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?