문제

<< 1 2 3 4 ... 15 16 17 ... 47 48 49 50 >>

<< 1 2 3 4 5 6 7 ... 47 48 49 50 >>

<< 1 2 3 4 ... 44 45 46 47 48 49 50 >>

(대담한 것은 선택된 페이지입니다)

이와 같은 스케일링 페이지 매김을 만드는 클리버 논리가 있습니까? 나는 이전에 이것들 중 하나를 만들었지 만 논리 진술의 혼란으로 끝났습니다.

내가 지금하고있는 언어는 PHP이지만 어떤 언어에 대한 사례 나 팁이 있다면, 감사 할 것입니다.

스케일링한다는 것은 몇 페이지 만있을 때를 의미합니다. 페이지 매김은 이것을 표시합니다.

<< 1 2 3 4 5 6 7 >>

페이지 수가 특정 지점으로 성장함에 따라 페이지 매김은 모든 숫자를 보여주는 것을 멈추고 나누기 시작합니다.

<< 1 2 3 4 ... 47 48 49 50 >>

<< 1 2 3 4 5 6 ... 47 48 49 50 >>

<< 1 2 3 4 5 6 7 8 ... 47 48 49 50 >>

<< 1 2 3 4 .. 7 8 9 ... 47 48 49 50 >>

<< 1 2 3 4 .. 15 16 17 ... 47 48 49 50 >>

<< 1 2 3 4 ... 44 45 46 47 48 49 50 >>

<< 1 2 3 4 ... 47 48 49 50 >>

(참고, 실제 숫자와 전후에 표시되는 수는 관련이 없습니다)

도움이 되었습니까?

해결책

코드 덩어리에 대해 죄송하지만 여기에 간다. 바라건대 의견이 어떻게 작동하는지 알려주기에 충분합니다. 의견을 남기고 좀 더 추가 할 수 있습니다.

    /**
     * Get a spread of pages, for when there are too many to list in a single <select>
     * Adapted from phpMyAdmin common.lib.php PMA_pageselector function
     *
     * @param integer total number of items
     * @param integer the current page
     * @param integer the total number of pages
     * @param integer the number of pages below which all pages should be listed
     * @param integer the number of pages to show at the start
     * @param integer the number of pages to show at the end
     * @param integer how often to show pages, as a percentage
     * @param integer the number to show around the current page
     */
    protected function pages($rows, $pageNow = 1, $nbTotalPage = 1, $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20, $range = 10)
    {
        if ($nbTotalPage < $showAll)
            return range(1, $nbTotalPage);

        // Always show the first $sliceStart pages
        $pages = range(1, $sliceStart);

        // Always show last $sliceStart pages
        for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++)
            $pages[] = $i;

        $i = $sliceStart;
        $x = $nbTotalPage - $sliceEnd;
        $met_boundary = false;
        while ($i <= $x)
        {
            if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range))
            {
                // If our pageselector comes near the current page, we use 1
                // counter increments
                $i++;
                $met_boundary = true;
            }
            else
            {
                // We add the percentate increment to our current page to
                // hop to the next one in range
                $i = $i + floor($nbTotalPage / $percent);

                // Make sure that we do not cross our boundaries.
                if ($i > ($pageNow - $range) && !$met_boundary)
                  $i = $pageNow - $range;
            }

            if ($i > 0 && $i <= $x)
                $pages[] = $i;
        }

        // Since because of ellipsing of the current page some numbers may be double,
        // we unify our array:
        sort($pages);
        return array_unique($pages);
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top