change count master/detail

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
danilo.macri
User
Posts: 93

change count master/detail

Post by danilo.macri »

hi guys, i want to change the detail count
I have three views:
tablemaster ( master)
table1 (detail)
table2all

I want in the detail counts of table one to count the data of the table2all view
I used the following code:
the ListOptions_Rendering() of tablemaster I entered

$this->table1_Count = ExecuteScalar("SELECT COUNT(*) FROM table2all");

it returns me this error:

C:\xampp\htdocs\detenuti\src\DbTableBase.php(561): Obsolete property: table1_Count, please use Container('table1')->Count.

why?


mobhar
User
Posts: 11660

Post by mobhar »

Because the table1_Count property is deprecated. You should use Container('table1')->Count instead.

So, change this code:
$this->table1_Count = ExecuteScalar("SELECT COUNT(*) FROM table2all");

to:
Container('table1')->Count = ExecuteScalar("SELECT COUNT(*) FROM table2all");


danilo.macri
User
Posts: 93

Post by danilo.macri »

I inserted the code in the master table

function ListOptions_Rendering()
{

Container('tablemaster')->Count = ExecuteScalar("SELECT COUNT(*) FROM tableall");

}

I've enabled datail record count but I'm left with the original count, not the one in the table..... why?


mobhar
User
Posts: 11660

Post by mobhar »

Try to put in ListOptions_Rendered server event.


danilo.macri
User
Posts: 93

Post by danilo.macri »

it does not work :(
do you have any other method to change the number of master / detail?


mobhar
User
Posts: 11660

Post by mobhar »

It should work. It seems you are wrong to use master table name. It should be detail table name.

danilo.macri wrote:

Container('tablemaster')->Count = ExecuteScalar("SELECT COUNT(*) FROM tableall");

You should change tablemaster to your detail table name.


danilo.macri
User
Posts: 93

Post by danilo.macri »

I inspected the page code;

// "detail_pad_sicattpass"
    $opt = $this->ListOptions["detail_pad_sicattpass"];
    if ($Security->allowList(CurrentProjectID() . 'pad_sicattpass')) {
        $body = $Language->phrase("DetailLink") . $Language->TablePhrase("pad_sicattpass", "TblCaption");
        if (!$this->ShowMultipleDetails) { // Skip loading record count if show multiple details
            $detailTbl = Container("pad_sicattpass");
            $detailFilter = $detailTbl->getDetailFilter($this);
            $detailTbl->setCurrentMasterTable($this->TableVar);
            $detailFilter = $detailTbl->applyUserIDFilters($detailFilter);
            $detailTbl->Count = $detailTbl->loadRecordCount($detailFilter);
            $body .= " " . str_replace("%c", Container("pad_sicattpass")->Count, $Language->phrase("DetailCount"));
        }
        $body = "<a class=\"btn btn-default ew-row-link ew-detail" . ($this->ListOptions->UseDropDownButton ? " dropdown-toggle" : "") . "\" data-action=\"list\" href=\"" . HtmlEncode("PadSicattpassList?" . Config("TABLE_SHOW_MASTER") . "=padiglioceconta&" . GetForeignKeyUrl("fk_idpadiglione", $this->idpadiglione->CurrentValue) . "") . "\">" . $body . "</a>";
        $links = "";
        $detailPage = Container("PadSicattpassGrid");
        if ($links != "") {
            $body .= "<button type=\"button\" class=\"dropdown-toggle btn btn-default ew-detail\" data-bs-toggle=\"dropdown\"></button>";
            $body .= "<ul class=\"dropdown-menu\">" . $links . "</ul>";
        } else {
            $body = preg_replace('/\b\s+dropdown-toggle\b/', "", $body);
        }
        $body = "<div class=\"btn-group btn-group-sm ew-btn-group\">" . $body . "</div>";
        $opt->Body = $body;
        if ($this->ShowMultipleDetails) {
            $opt->Visible = false;
        }
    }

to change the count, in the master table I inserted this code:

/ /ListOptions Rendering event
public function listOptionsRendering()
{
Container("pad_sicattpass")->Count = ExecuteScalar("SELECT COUNT(*) FROM anagraficadetenuti");
}

this doesn't work..... do you know why?


mobhar
User
Posts: 11660

Post by mobhar »

Are you sure pad_sicattpass is the detail table name?


danilo.macri
User
Posts: 93

Post by danilo.macri »

Yes, this is the code that automatically generates phpmaker2023... I should change the value of

$body .= "&nbsp;" . str_replace("%c", Container("pad_sicattpass")->Count, $Language->phrase("DetailCount"));


mobhar
User
Posts: 11660

Post by mobhar »

It seems you have to change it from the generated code for such case, since there are no server events that can override it.


Post Reply