面板折叠后,ExtJS删除文本并将项添加到标题中

时间:2015-07-22 05:57:47

标签: javascript css extjs extjs5

我使用Ext5,我有一个问题。面板折叠后是否可以删除文本并将项目添加到面板标题中?

比较代码,东面板是可折叠的。我想删除文本并在折叠后将项目添加到标题中。

include 'databaseconnect.php';

// How many adjacent pages should be shown on each side?

$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$bodytypefilter = $_POST['bodytype'];
$query_str = " WHERE ";
$query_str.= "body_type='$bodytypefilter'";
$str.= "&bodytype=" . $bodytypefilter;
$targetpage = $_SERVER["PHP_SELF"] . "?" . $str;
$total_pages = mysql_fetch_array(mysql_query("SELECT count(*) as num from lookdescrip join createdlook ON createdlook.product_id1=lookdescrip.id " . $query_str));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$limit = 1; //how many items to show per page

if (isset($_GET['page'])) {
    $page = $_GET['page'];
}
else {

    // set proper default value if it was not set

    $page = '0';
}

if ($page) $start = ($page - 1) * $limit; //first item to display on this page
else $start = 0;

// if no page var is given, set start to 0

$valid = "";
$valid = true;
$sql1 = "SELECT * from lookdescrip join createdlook ON createdlook.product_id1=lookdescrip.id" . $query_str . " LIMIT $start, $limit";

if ($valid) {
    $result1 = mysql_query($sql1);
    /* Setup page vars for display. */
    if ($page == 0) $page = 1; //if no page var is given, default to 1.
    $prev = $page - 1; //previous page is page - 1
    $next = $page + 1; //next page is page + 1
    $lastpage = ceil($total_pages / $limit); //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1; //last page minus 1
    /*
    Now we apply our rules and draw the pagination object.
    We're actually saving the code to a variable in case we want to draw it more than once.
    */
    $pagination = "";
    if ($lastpage > 1) {
        $pagination.= "<div class=\"pagination\">";

        // previous button

        if ($page > 1) $pagination.= "<a href=\"$targetpage&page=$prev\">� previous</a>";
        else $pagination.= "<span class=\"disabled\">� previous</span>";

        // pages

        if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
        {
            for ($counter = 1; $counter <= $lastpage; $counter++) {
                if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>";
                else $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
            }
        }
        elseif ($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
        {

            // close to beginning; only hide later pages

            if ($page < 1 + ($adjacents * 2)) {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
                    if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>";
                    else $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
                }

                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";
            }

            // in middle; hide some front and some back

            elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
                    if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>";
                    else $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
                }

                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";
            }

            // close to end; only hide early pages

            else {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
                    if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>";
                    else $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
                }
            }
        }

        // next button

        if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage&page=$next\">next �</a>";
        else $pagination.= "<span class=\"disabled\">next �</span>";
        $pagination.= "</div>\n";
    }

    $images = array();
    $index = 0;
    while ($row = mysql_fetch_assoc($result1)) // loop to give you the data in an associative array so you can use it however.
    {
        $images[$index] = $row;
        $index++;
    }

    $rows = mysql_num_rows($result1);
    foreach($images as & $value) {
        echo $value['look_id']
    }
}
<?=$pagination?>

更新

在这种情况下,我将按钮添加到标题中,但是当面板折叠时按钮消失了。面板折叠时,有没有办法在组件中显示或添加组件?

Ext.create('Ext.container.Viewport', {
    layout: 'border',
    items: [{
        region: 'east',
        title: 'East Panel',
        collapsible: true,
        split: true,
        width: 150
    }, {
        region: 'center',
        xtype: 'tabpanel', // TabPanel itself has no title
        activeTab: 0,      // First tab active by default
        items: {
            title: 'Default Tab',
            html: 'The first tab\'s content. Others may be added dynamically'
        }
    }]
});

这是fiddle

由于

2 个答案:

答案 0 :(得分:3)

请参阅&#34;占位符&#34; Ext.panel.Panel类中的相关配置。以下是您修改后的代码。

Ext.create('Ext.container.Viewport', {
    layout: 'border',
    items: [{
        region: 'east',
        title: 'East Panel',
        collapsible: true,
        collapseMode:'placeholder',// set collapseMode to placeholder
        split: true,
        width: 300,
        placeholder:{ // Try different components and layout configs
            width:100,
            items:[{
                xtype:'button',
                text:'Button 1'
            }]
        }
        /*header: {
            items: [{
                xtype: 'button'
            }, {
                xtype: 'button'
            }]
        }*/
    }, {
        region: 'center',
        xtype: 'tabpanel', // TabPanel itself has no title
        activeTab: 0,      // First tab active by default
        items: {
            title: 'Default Tab',
            html: 'The first tab\'s content. Others may be added dynamically'
        }
    }]
});

答案 1 :(得分:0)

您看到折叠的标题实际上是为此目的而创建的另一个Ext.panel.Header实例。我试图找到一些配置来定制它,但Ext.panel.Panel并没有考虑到它。

所以你必须覆盖创建这个阅读器的方法,我发现它被称为createReExpander。这是一个难以覆盖的大方法,无需重写很多东西,但它可以完成。

我尝试在标题中添加按钮,结果看起来不太好,但至少它们已经创建了! 因此,如果您不需要文本,我建议您使用tools代替按钮。