mirror of https://github.com/ElemeFE/element
Pagination: add hide-on-single-page attribute (#15096)
parent
2a65c9df7e
commit
e5385e8531
|
@ -140,6 +140,34 @@ Add more modules based on your scenario.
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Hide pagination when there is only one page
|
||||||
|
|
||||||
|
When there is only one page, hide the pagination by setting the `hide-on-single-page` attribute.
|
||||||
|
|
||||||
|
:::demo
|
||||||
|
```html
|
||||||
|
<div>
|
||||||
|
<el-switch v-model="value">
|
||||||
|
</el-switch>
|
||||||
|
<el-pagination
|
||||||
|
:hide-on-single-page="value"
|
||||||
|
:total="5"
|
||||||
|
layout="prev, pager, next">
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|--------------------|----------------------------------------------------------|-------------------|-------------|--------|
|
|--------------------|----------------------------------------------------------|-------------------|-------------|--------|
|
||||||
|
@ -156,6 +184,7 @@ Add more modules based on your scenario.
|
||||||
| prev-text | text for the prev button | string | — | — |
|
| prev-text | text for the prev button | string | — | — |
|
||||||
| next-text | text for the next button | string | — | — |
|
| next-text | text for the next button | string | — | — |
|
||||||
| disabled | whether Pagination is disabled | boolean | — | false |
|
| disabled | whether Pagination is disabled | boolean | — | false |
|
||||||
|
| hide-on-single-page | whether to hide when there's only one page | boolean | — | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
| Event Name | Description | Parameters |
|
| Event Name | Description | Parameters |
|
||||||
|
|
|
@ -125,6 +125,34 @@ Agrega más modulos basados en su escenario.
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
### Hide pagination when there is only one page
|
||||||
|
|
||||||
|
When there is only one page, hide the pagination by setting the `hide-on-single-page` attribute.
|
||||||
|
|
||||||
|
:::demo
|
||||||
|
```html
|
||||||
|
<div>
|
||||||
|
<el-switch v-model="value">
|
||||||
|
</el-switch>
|
||||||
|
<el-pagination
|
||||||
|
:hide-on-single-page="value"
|
||||||
|
:total="5"
|
||||||
|
layout="prev, pager, next">
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
### Atributos
|
### Atributos
|
||||||
|
@ -141,7 +169,8 @@ Agrega más modulos basados en su escenario.
|
||||||
| popper-class | clase propia para el `dropdown` del `select` del número de páginas | string | — | — |
|
| popper-class | clase propia para el `dropdown` del `select` del número de páginas | string | — | — |
|
||||||
| prev-text | texto para el botón `prev` | string | — | — |
|
| prev-text | texto para el botón `prev` | string | — | — |
|
||||||
| next-text | texto para el botón `next` | string | — | — |
|
| next-text | texto para el botón `next` | string | — | — |
|
||||||
| disabled | si Pagination esta disabled | boolean | — | false |
|
| disabled | si Pagination esta disabled | boolean | — | false |
|
||||||
|
| hide-on-single-page | whether to hide when there's only one page | boolean |— | - |
|
||||||
|
|
||||||
### Eventos
|
### Eventos
|
||||||
| Nombre del evento | Descripción | Parámetros |
|
| Nombre del evento | Descripción | Parámetros |
|
||||||
|
|
|
@ -144,6 +144,34 @@ Vous pouvez ajouter plus de modules suivant vos besoins.
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Hide pagination when there is only one page
|
||||||
|
|
||||||
|
When there is only one page, hide the pagination by setting the `hide-on-single-page` attribute.
|
||||||
|
|
||||||
|
:::demo
|
||||||
|
```html
|
||||||
|
<div>
|
||||||
|
<el-switch v-model="value">
|
||||||
|
</el-switch>
|
||||||
|
<el-pagination
|
||||||
|
:hide-on-single-page="value"
|
||||||
|
:total="5"
|
||||||
|
layout="prev, pager, next">
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
### Attributs
|
### Attributs
|
||||||
|
|
||||||
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
||||||
|
@ -161,6 +189,7 @@ Vous pouvez ajouter plus de modules suivant vos besoins.
|
||||||
| prev-text | Texte du bouton prev. | string | — | — |
|
| prev-text | Texte du bouton prev. | string | — | — |
|
||||||
| next-text | Texte du bouton next. | string | — | — |
|
| next-text | Texte du bouton next. | string | — | — |
|
||||||
| disabled | Si la pagination est désactivée. | boolean | — | false |
|
| disabled | Si la pagination est désactivée. | boolean | — | false |
|
||||||
|
| hide-on-single-page | whether to hide when there's only one page | boolean | — | - |
|
||||||
|
|
||||||
### Évènements
|
### Évènements
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,34 @@
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### 当只有一页时隐藏分页
|
||||||
|
|
||||||
|
当只有一页时,通过设置 `hide-on-single-page` 属性来隐藏分页。
|
||||||
|
|
||||||
|
:::demo
|
||||||
|
```html
|
||||||
|
<div>
|
||||||
|
<el-switch v-model="value">
|
||||||
|
</el-switch>
|
||||||
|
<el-pagination
|
||||||
|
:hide-on-single-page="value"
|
||||||
|
:total="5"
|
||||||
|
layout="prev, pager, next">
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||||
|--------------------|----------------------------------------------------------|-------------------|-------------|--------|
|
|--------------------|----------------------------------------------------------|-------------------|-------------|--------|
|
||||||
|
@ -156,6 +184,7 @@
|
||||||
| prev-text | 替代图标显示的上一页文字 | string | — | — |
|
| prev-text | 替代图标显示的上一页文字 | string | — | — |
|
||||||
| next-text | 替代图标显示的下一页文字 | string | — | — |
|
| next-text | 替代图标显示的下一页文字 | string | — | — |
|
||||||
| disabled | 是否禁用 | boolean | — | false |
|
| disabled | 是否禁用 | boolean | — | false |
|
||||||
|
| hide-on-single-page | 只有一页时是否隐藏 | boolean | — | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
| 事件名称 | 说明 | 回调参数 |
|
| 事件名称 | 说明 | 回调参数 |
|
||||||
|
|
|
@ -52,7 +52,9 @@ export default {
|
||||||
|
|
||||||
background: Boolean,
|
background: Boolean,
|
||||||
|
|
||||||
disabled: Boolean
|
disabled: Boolean,
|
||||||
|
|
||||||
|
hideOnSinglePage: Boolean
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
@ -65,12 +67,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
|
const layout = this.layout;
|
||||||
|
if (!layout) return null;
|
||||||
|
if (this.hideOnSinglePage && (!this.internalPageCount || this.internalPageCount === 1)) return null;
|
||||||
|
|
||||||
let template = <div class={['el-pagination', {
|
let template = <div class={['el-pagination', {
|
||||||
'is-background': this.background,
|
'is-background': this.background,
|
||||||
'el-pagination--small': this.small
|
'el-pagination--small': this.small
|
||||||
}] }></div>;
|
}] }></div>;
|
||||||
const layout = this.layout || '';
|
|
||||||
if (!layout) return;
|
|
||||||
const TEMPLATE_MAP = {
|
const TEMPLATE_MAP = {
|
||||||
prev: <prev></prev>,
|
prev: <prev></prev>,
|
||||||
jumper: <jumper></jumper>,
|
jumper: <jumper></jumper>,
|
||||||
|
|
|
@ -421,6 +421,17 @@ describe('Pagination', () => {
|
||||||
expect(vm.page).to.equal(1);
|
expect(vm.page).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('hideOnSinglePage', () => {
|
||||||
|
vm = createVue({
|
||||||
|
template: `
|
||||||
|
<el-pagination
|
||||||
|
hide-on-single-page
|
||||||
|
:total="1" />
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(vm.$el.nodeType).to.be.equal(window.Node.COMMENT_NODE);
|
||||||
|
});
|
||||||
|
|
||||||
describe('click pager', () => {
|
describe('click pager', () => {
|
||||||
it('click ul', () => {
|
it('click ul', () => {
|
||||||
vm = createTest(Pagination, {
|
vm = createTest(Pagination, {
|
||||||
|
|
|
@ -37,4 +37,7 @@ export declare class ElPagination extends ElementUIComponent {
|
||||||
|
|
||||||
/** Text for the prev button */
|
/** Text for the prev button */
|
||||||
nextText: string
|
nextText: string
|
||||||
|
|
||||||
|
/** Whether to hide when thers's only one page */
|
||||||
|
hideOnSinglePage: boolean
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue