sjaakp / yii2-alphapager

Alphabetic paging with Yii 2.0
https://sjaakpriester.nl/software/alphapager
MIT License
18 stars 6 forks source link

Custom digits #2

Closed chuprik closed 9 years ago

chuprik commented 9 years ago

Hi! These changes allow to use any digits (I needed letters of the Russian alphabet) to generate a pager links.

Usage:

$dataProvider = new ActiveDataProvider([
    'query' => News::find(),
    'alphaAttribute' => 'title',
    'alphaDigits' => ['А', 'Б', 'В'],
]);

Looks this:

Alt text

sjaakp commented 9 years ago

Thanks. But frankly, I disagree. You can set any other digits just as well by using DataProvider::alphaPages and AlphaPager::postButtons.


Sjaak Priester

sjaak@sjaakpriester.nl

Van: Constantine Chuprik [mailto:notifications@github.com] Verzonden: zondag 21 juni 2015 16:53 Aan: sjaakp/yii2-alphapager Onderwerp: [yii2-alphapager] Custom digits (#2)

Hi! These changes allow to use any digits (I needed letters of the Russian alphabet) to generate a pager links.

Usage:

$dataProvider = new ActiveDataProvider([ 'query' => News::find(), 'alphaAttribute' => 'title', 'alphaDigits' => ['А', 'Б', 'В'], ]);

Looks this:

https://camo.githubusercontent.com/39003bdffd6a1cce2eeb744d943ed0f40e02eec5/68747470733a2f2f6d6f6e6f736e61702e636f6d2f66696c652f615667796a47573551626e70335463646b46657978446d7554464c654a4e2e706e67 Alt text


You can view, comment on, or merge this pull request online at:

https://github.com/sjaakp/yii2-alphapager/pull/2

Commit Summary

File Changes

Patch Links:

— Reply to this email directly or view it on GitHub https://github.com/sjaakp/yii2-alphapager/pull/2 . https://github.com/notifications/beacon/AFU71ji-EGC9c5kcrvW0AFl9aKqGU928ks5oVsdRgaJpZM4FIVBv.gif

chuprik commented 9 years ago

But it's not right. Look the your code:

$pages = array_merge($this->preButtons, range('A', 'Z'), $digs, $this->postButtons);

range('A', 'Z') is definitely will be added to the pages array. but it is not always necessary for example — I need Russian digits only. I could override run() but why? I think it should be customizable.

sjaakp commented 9 years ago

As an example, here is how you might make buttons for Roman numerals, showing ‘normal’ numeric pages:

$dataProvider = new ActiveDataProvider([ 'query' => Person::find(), 'alphaAttribute' => 'last_name', 'alphaPages' => [ 'd1' => [ // keys should start with alpha character 'label' => 'I', 'pattern' => '1' ], 'd2' => [ 'label' => 'II', 'pattern' => '2' ], // .. 'd7' => [ 'label' => 'VII', 'pattern' => '7' ], // .. 'd9' => [ 'label' => 'IX', 'pattern' => '9' ], ] ]);

<?= AlphaPager::widget([
    'dataProvider' => $dataProvider,
    'postButtons' => array_map(function($v) { return 'd' . $v; }, range(1, 9))
]) ?>

It’s a little bit involved, I agree, but not impossible.


Sjaak Priester

sjaak@sjaakpriester.nl

Van: Constantine Chuprik [mailto:notifications@github.com] Verzonden: maandag 22 juni 2015 10:59 Aan: sjaakp/yii2-alphapager CC: Sjaak Priester Onderwerp: Re: [yii2-alphapager] Custom digits (#2)

but it's not right look the your code:

$pages = array_merge($this->preButtons, range('A', 'Z'), $digs, $this->postButtons);

range('A', 'Z') is definitely will be added to the array. but it is not always necessary for example — I need Russian digits only. I could override run() but why? I think it should be customizable.

— Reply to this email directly or view it on GitHub https://github.com/sjaakp/yii2-alphapager/pull/2#issuecomment-114044855 . https://github.com/notifications/beacon/AFU71k_KtQjPFyynPyFEfjtkMt4p8C3Uks5oV8XTgaJpZM4FIVBv.gif

chuprik commented 9 years ago

I just checked your option. It isn't help me :) Look result:

Alt text

It's result of copy/paste your example.

I mean I want to do pager like that:

Alt text

And my pull request solve this problem. Current pager must display all English digits (range('A', 'Z')). Sometimes it is not required.

sjaakp commented 9 years ago

Sorry, I misunderstood you completely. What you call ‘digits’, I call ‘alphabetic characters’, hence the confusion. English isn’t my native language.

Anyway, I merged your pull request.


Sjaak Priester

sjaak@sjaakpriester.nl

Van: Constantine Chuprik [mailto:notifications@github.com] Verzonden: maandag 22 juni 2015 17:23 Aan: sjaakp/yii2-alphapager CC: Sjaak Priester Onderwerp: Re: [yii2-alphapager] Custom digits (#2)

I just checked your option. It isn't help me :) Look result:

https://camo.githubusercontent.com/f494dc5a6a0b0187b557c26a98a16ec4ab80e485/68747470733a2f2f6d6f6e6f736e61702e636f6d2f66696c652f674d75317150427a62697a747061364c79637542524778446f53475753632e706e67 Alt text

It's result of copy/paste your example.

I mean I want to do pager like that:

https://camo.githubusercontent.com/5eceb36c6453b5d8aff4e26ca989ac5b1bb17b70/68747470733a2f2f6d6f6e6f736e61702e636f6d2f66696c652f6e3359425665456f4c44644a3870563171643343537775574e52374c74672e706e67 Alt text

And my pull request solve this problem. Current pager must display all English digits (range('A', 'Z')). Sometimes it is not required.

— Reply to this email directly or view it on GitHub https://github.com/sjaakp/yii2-alphapager/pull/2#issuecomment-114152856 . https://github.com/notifications/beacon/AFU71hg0MqUHMPIOQJM6pb2bF_5GjIoqks5oWB-7gaJpZM4FIVBv.gif

chuprik commented 9 years ago

no problem. English isn't my native language too. I call it 'digits' because you call in the your code :)

thanks for the merge :)