Giter Site home page Giter Site logo

terryz / v-selectpage Goto Github PK

View Code? Open in Web Editor NEW
241.0 6.0 63.0 879 KB

SelectPage for Vue, a select items components provides the list of items with pagination

Home Page: https://terryz.github.io/docs-vue3/selectpage/

License: MIT License

JavaScript 84.95% HTML 0.37% Vue 5.67% Sass 9.02%
javascript vuejs selector tableview i18n pagination tags multiple front-end

v-selectpage's Introduction

SelectPage

CircleCI code coverage npm version

SelectPage for Vue3, a select items components provides the list of items with pagination

Financial Contributors on Open Collective JavaScript Style Guide npm download

If you are using vue 2.x version, please use v-selectpage 2.x version instead









Examples and Documentation

Documentation and examples please visit below sites

The jQuery version: SelectPage

Features

  • Display contents with pagination
  • I18n support
  • Select single / multiple options
  • Tags form for multiple selection
  • Keyboard navigation
  • Searchable
  • Provide display forms such as list view and table view
  • Customization of row / cell content rendering
  • Core module that can be used independently

I18n support languages

  • Chinese Simplified
  • English
  • Japanese
  • Arabic
  • Spanish
  • German
  • Romanian
  • French
  • Portuguese-Brazil
  • Polish
  • Dutch
  • Chinese Traditional
  • Russian
  • Turkish

Installation

https://nodei.co/npm/v-selectpage.png?downloads=true&downloadRank=true&stars=true

Install v-selectpage to your project

# npm
npm i v-selectpage
# yarn
yarn add v-selectpage
# pnpm
pnpm add v-selectpage

Usage

Quick start example

<template>
  <SelectPageList
    key-prop="id"
    label-prop="name"
    @fetch-data="fetchData"
  />
</template>

<script setup lang="ts">
import { SelectPageList } from 'v-selectpage'
import type { PageParameters, FetchDataCallback } from 'v-selectpage'

function fetchData (data: PageParameters, callback: FetchDataCallback) {
  // pagination information and search keyword
  const { search, pageNumber, pageSize } = data

  // request parameters
  const parameters = {
    search,
    pageNumber,
    pageSize,
    ...
  }

  // fetch data list with pagination state
  doDataRequest(parameters)
    .then(resp => {
      /**
       * Return data format for example
       * {
       *   list: object[], // current page data list
       *   total: number // result count
       * }
       */
      callback(resp.list, resp.total)
    })
    .catch(() => {
      // clear the data list if necessary when request fails
      callback([], 0)
    })
}
</script>

Set default selected items

<template>
  <SelectPageTable
    language="zh-chs"
    v-model="selected"
    :multiple="true"
    :columns="columns"
    @fetch-data="fetchData"
    @fetch-selected-data="fetchSelectedData"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { SelectPageTable } from 'v-selectpage'
import type {
  SelectPageKey, FetchSelectedDataCallback,
  PageParameters, FetchDataCallback, SelectPageTableColumn
} from 'v-selectpage'

const selected = ref<SelectPageKey[]>([2, 4, 7])
const columns: SelectPageTableColumn[] = [
  { title: 'Id', data: 'id' },
  { title: 'Team name', data: row => `${row.abbr} - ${row.name}`, width: 250 },
  { title: 'Description', data: 'desc' }
]

// fetch current page data
function fetchData (data: PageParameters, callback: FetchDataCallback) {
  ...
}
// fetch selected items data
function fetchSelectedData (keys: SelectPageKey[], callback: FetchSelectedDataCallback) {
  // get data models by keys
  doDataRequest({ keys }).then(resp => {
    callback(resp)
  })
}
</script>

Plugin preview

List view for Single selection

single

List view for multiple selection with tags form

multiple

Table view for single selection

table

Dependencies

License

license

v-selectpage's People

Contributors

atgxichenfan avatar eugeniob avatar liviuroman avatar mhelaiwa avatar monkeywithacupcake avatar plegenza avatar ridaamirini avatar terryz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

v-selectpage's Issues

Selectpage's v-model overrides the default value continued...

Thank you very much for the fix #8 . I think it has helped.

I do experience the same behavior time to time though. I had to apply a temporary fix to make the component work in my application.

watch: {
    'models'() {
        if(Object.keys(this.models).length > 0) {
            setTimeout(() => {
                this.input.model_id = this.settings.properties.model_id
            }, 0)
        }
    }
}

So, when the data arrives, I simply assign the selected model id to input.model_id because at first this component tries to overrides input.model_id to an empty string. This way with setTimeout(fn, 0), I applied a temporary fix!

Can you tell me if I'm doing something wrong or not using your component properly?

Table-view issues

When its in table-view

  • search does not work
  • select all (in page) option does not work

How to change language to English

I have issue configuring the language option to English.
import vSelectPage from 'v-selectpage'; Vue.use(vSelectPage, {lang:'en'}) ;
It is display the default Chinese

z-index problem nested

hello guys,
i had a problem about front side of page. i have modal page and i am bringing Vselectpage on this page but dropdown is opening behind modal. After i zoom in/out the vselectpage become visible but its still under modal. Could you please help me.

Ekran Alıntısı

tb-columns doesn't invoke data function on Table

Hello,

this doesn't work on tb-columns property:

[
  {
     title: 'Test',
    data(row) {
        return row.firstname + '  ' + row.lastname;
     }
   }
]

I think its caused by this line

<td :key="idx" v-for="(col,idx) in tbColumns" v-html="row[col.data]"></td>

It should also call renderCell()

下载了v-selectpage 后本地跑图标会出不来

hi Terry Zeng:
我下载了本项目的源码。在我项目中使用,会出现以下图片的问题,用npm下载的包,定义全局就不会出现问题!麻烦请教一下别人是否有反馈过这样的问题!
image

v-selectpage 打包后的问题

我的项目是vue+element-ui的项目,我想问下是否依赖element-ui,为了优化性能 #我把element-ui改成cdn链接,并且把main.js里面引入element-ui给注释,在webpack配置里用了externals,但是打包后此组件的input框没有出来,找了好久没有找到原因,请教一下原因。
![Uploading 02eb38f0505
0e1c0cc0116b49fe91de1583f21e3e5
4589fc616340d86cbaa25563b833fb7

3f6c3d55de4c966b7e18.png…]()

单选的时候会发送多个数据

一个表单提交成功后,编辑获取详情,不操作v-selectpage组件,会直接发送data传过来的所有数据。这么明显的bug

<v-selectpage
    ref="selectPage"
    v-model="pageValue"
    class="my-v-select"
    data="/dev-api/aeledger/amassetview/getAmassetList"
    key-field="lngamassetid"
    show-field="stramassetcode"
    search-field="keyword"
    placeholder="请选择"
    :multiple="false"
    :disabled="disabled"
    :result-format="resultFormat"
    @values="getRowInfo"
  />

method

resultFormat(resp) {
      if (resp && resp.data) return { totalRow: resp.data.data.total, list: resp.data.data.rows }
    },
    change(val) {
      if (val) {
        localStorage.setItem('assetDeparmentId', val)
        this.$refs.selectPage.dataLoad(this.$refs.assetcode, '/dev-api/aeledger/amassetview/getAmassetList').then(res => {
          this.$refs.selectPage.list = res.data.data.rows
          this.$refs.selectPage.totalRows = res.data.data.total
        })
      }
    },
    getRowInfo(val) {
      this.$emit('select', val)
    }

v-model is not updating the value

Bug

The v-model didn't work the value would disappear after I click on the option, I tried so many things with no success
here is an example
https://codesandbox.io/s/heuristic-cookies-q48ez9

Solution

After banging my head against the wall I discovered that the data should not be computed value
I was doing

<v-selectpage
  v-model="selectedClientId"
  :data="options.map(el => ({
      name: el.name,
      id: String(el.id)
    }))"
  placeholder=" "
  title=" "
/>

I should do

<v-selectpage
  v-model="selectedClientId"
  :data="options"
  key-field="id" 
  show-field="name"
  placeholder=" "
  title=" "
/>

Search not working in combination with modal

I'm using bootstrap-vue modal https://bootstrap-vue.js.org/docs/components/modal/ together with your plugin and search is not working, I can't even click on search input field, and this is because of d-block class that's used on modal, if I go to inspect of that class and disable and again enable it's css search is working.

http://prntscr.com/mdp78n

Code for this look's like this

    <template>
    <b-modal :title="trans.get('__JSON__.Create new product group')"
             id="newGroupModal"
             ref="newGroupModal"
             @hidden="onHidden"
             @shown="onShow"
             hide-footer>

      <b-form @submit.prevent="onSubmit">

        <b-form-group :label="trans.get('__JSON__.Name')">

          <b-input v-model="form.name"
                   required
                   :placeholder="trans.get('__JSON__.Name')"></b-input>
        </b-form-group>

        <b-form-group :label="trans.get('__JSON__.Attributes')">

          <v-selectpage :data="attributes"
                        :multiple="true"
                        language="en"
                        ref="attributes"
                        v-model="form.attributes">
          </v-selectpage>
        </b-form-group>

        <b-form-group :label="trans.get('__JSON__.Rackbeat number')">

          <b-input v-model="form.rackbeat_number"
                   required
                   :placeholder="trans.get('__JSON__.Rackbeat number')"></b-input>
        </b-form-group>

        <b-btn type="submit"
               variant="info">{{ trans.get('__JSON__.Submit') }}
        </b-btn>
      </b-form>
    </b-modal>
    </template>
    <script>
    export default {
        name:    'new-group-modal',
        props:   {

            url:        {

                default: '',
                type:    String,
            },
            attributes: {

                default: [],
                type:    Array,
            },
        },
        data() {

            return {

                form: {

                    name:            null,
                    attributes:      '',
                    rackbeat_number: null,
                },
            };
        },
        methods: {

            onSubmit() {

                this.form.attributes = (this.form.attributes !== '') ? this.form.attributes.split( ',' ) : [];

                this.$http.post( this.url, this.form ).then( response => {

                    this.form = {

                        name:            null,
                        attributes:      '',
                        rackbeat_number: null,
                    };

                    this.$refs.attributes.$emit( 'clear' );
                    this.$refs.attributes.pageChange( 1 );
                    this.$eventHub.$emit( 'group-created', response.data.data );
                    this.$refs.newGroupModal.hide();
                    this.$toasted.show( this.trans.get( '__JSON__.Product group created successfully' ), {

                        duration: 4000,
                        type:     'success',
                    } );
                }, response => {

                    if ( Array.isArray( this.form.attributes ) ) {

                        this.form.attributes = this.form.attributes.join( ',' );
                    }

                    let _this = this;

                    if ( response.data.errors !== undefined ) {

                        Object.values( response.data.errors ).forEach( function ( error ) {

                            _this.$toasted.show( error[ 0 ], {

                                duration: 4000,
                                type:     'error',
                            } );
                        } );
                    } else if ( response.data.message !== undefined ) {

                        _this.$toasted.show( response.data.message, {

                            duration: 4000,
                            type:     'error',
                        } );
                    }
                } );
            },
            onHidden() {

                this.$refs.attributes.$emit( 'clear' );
                this.$refs.attributes.pageChange( 1 );
            },
        },
    };
    </script>

多选下清除picked后自动展示出下拉框

多选下拉选择的使用中,使用了this.$refs.sp.remove()或设置this.$refs.sp.picked=[]后,会自动跳出下拉框dropdown来,请问如果不想要这个自动展示要怎么做?

result-format的格式要求具体应该始要怎么样的

{    totalRow: 100,    list:[        {...},        {...},        {...}    ]}

--

根据文档的说法是插件识别这样的格式

然后我后端接口的提供格式是

{
    "success": true,
    "message": "操作成功!",
    "code": 0,
    "result": null,
    "list": {
        "records": [
            {
                "id": "15588446194750",
                "customercode": "kehu1",
                "customername": "客户1",
                "customerabbreviation": "客户1",
                "accountperiod": "",
                "paymentmethod": "",
                "creditrating": "",
                "creditline": "",
                "creditcontrolmode": "",
                "createTime": "2019-05-26 12:24:44",
                "createBy": "jeecg-boot",
                "updateBy": null,
                "updateTime": null,
                "sysOrgCode": ""
            },
            {
                "id": "15588446692350",
                "customercode": "546",
                "customername": "12",
                "customerabbreviation": "645",
                "accountperiod": "564",
                "paymentmethod": "632",
                "creditrating": "3453",
                "creditline": "",
                "creditcontrolmode": "",
                "createTime": "2019-05-26 12:24:46",
                "createBy": "jeecg-boot",
                "updateBy": null,
                "updateTime": null,
                "sysOrgCode": ""
            },
            {
                "id": "a948b8f2434ab0fe47f2c0eced5742a3",
                "customercode": "867",
                "customername": "456",
                "customerabbreviation": "56",
                "accountperiod": "56",
                "paymentmethod": "456",
                "creditrating": "456",
                "creditline": "456",
                "creditcontrolmode": "456",
                "createTime": "2019-05-26 12:23:29",
                "createBy": "jeecg-boot",
                "updateBy": null,
                "updateTime": null,
                "sysOrgCode": "456"
            }
        ],
        "total": 3,
        "size": 10,
        "current": 1,
        "searchCount": true,
        "pages": 1
    },
    "timestamp": 1559652484764
}

请问是返回的数据只需要有totalRow 和list就可以了还是只能是totalRow和list

Feature Request: AppendTo property

I am working on a website with RTL interface. And Unfortunately this beautiful component plugin doesn't support RTL languages.

So I thought providing a feature like appendTo which enables me to append the list to the current parent will help me to override some css properties to make it possible to show the list in a proper way inside an RTL interface.

Feature Request: Define a list width

Hello,

I would like to suggest the ability to add a fixed width to the list. Otherwise, when you go through different pages, the container will always keep changing the width and that does not provide a good user experience.

Thanks

服务端模式完全不进行数据拉取,dataLoad函数没有反应

代码如下,我是以组件的形式引用v-selectpage,我按照文档的说明设置了url和data-load函数,但是我发现没有反应,具体表现为data-load函数设置的log没有在浏览器调试的日志窗口打印,并且浏览器的调试器的network显示,并没有向我设置的地址发出任何请求,我到底哪里没设置对?

<template>
    <v-selectpage
      v-model="listQuery.merchantId"
      title="选择商户"
      key-field="id"
      show-field="name"
      search-field="name"
      :tb-columns="[
        { title: 'id', data: 'id' },
        { title: 'name', data: 'name' },
      ]"
      data="http://47.115.111.141:8082/merchant/listForSelect"
      :data-load="vSelectpageDataload"
      :result-format="resultFormat"
      style="width: 200px"
      class="filter-item"
    />
  </div>
</template>
<script>
import { SelectPage } from 'v-selectpage'
import axios from 'axios'

export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  components: {
    'v-selectpage': SelectPage
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 20,
        importance: undefined,
        merchantId: undefined,
        searchType: undefined,
        searchStr: undefined,
        type: undefined,
        sort: '+id'
      },
      list: [
        { id: 1, name: 'Chicago Bulls', desc: '芝加哥公牛' },
        { id: 2, name: 'Cleveland Cavaliers', desc: '克里夫兰骑士' },

      ]
    }
  },
  methods: {
    vSelectpageDataload(vue, data, params) {
      console.log('执行vSelectpageDataload')
      return new Promise((resolve, reject) => {
        axios.post(data, params).then(resp => resolve(resp), resp => reject(resp))
      })

    },
    resultFormat(resp) {
      console.log('resultFormat')
      if (resp && resp.data) return resp.data.values.gridResult
    }
  }
}
</script>

Preload images on multiple upload

Is there a way to show images that are already on the server in the multiple upload? For example, when using the uploader for an existing record that already has files attached.
In other words, is there an event listener or method that can be called to fill the uploadedFiles array?

组件能否自定义一个方法?

在表格中使用此组件,我需要自定义一个方法来获取当前行,但是现在不能自定义方法,所以无法实现获取row 希望能增加一个自定义方法

进入页面赋初始化值有问题

代码如附件,我进入页面给realmId 赋值为1192013224205352962
但是我上面的/live_code/codeliverealm/list 返回的数值是
0.
{realmId: "1192011114952785921"
realmUrl: (...)
}
1:
{realmId: "1192013224205352962"
realmUrl: (...)
}
假设这里有两笔数据
此时我们看realmId的值他就发生了变化,成了realmId:"1192011114952785921,1192013224205352962"

变成了两个ID了?????这要重新选择下拉框。realmId的值才能变成变成单个,而不是现在有两个。不知道为什么这里会这样?有没有人遇到过这样的问题,如果你进页面不赋值的话,就没问题,

demo.txt

dataload and v-model 有bug

remote 方法的 最后一行代码
that.picked = tmpObj.list, 页面全选中了,没有看明白这里要干啥

我使用 v-model 远程加载, dataload是一个url,

选中一项之后, 会触发 watch->picked 方法
picked(val) {
if (this.message && this.maxSelectLimit && val.length < this.maxSelectLimit) this.message = ''
let that = this
this.$emit('input', val.map((value) => value[that.keyField]).join(','))
this.$emit('values', this.picked.concat())
},

通过v-modal ,该组件接受的value改变,触发
watch->value ->this.initSelection 然后走到remote的最后一行, 导致页面全选了

服务端数据模式 数据初始化异常

官网的样例,在data 本地模式中,v-model绑定的数据,在select框初始化时会呈现数据,但是用 :data 服务端数据模式下,v-model绑定的数据初始化会出现异常

BootstrapTheme ?

Hi, is there an option to use the default Bootstrap theme of the select component?
Thanks.

不显示组件

我引入组件并在vue使用,结果通过鼠标可以点击到控件 但是控件并没有显示出来,我尝试过样式去调,但是没有效果

V-model and async messed up selected value

Hi, sorry if this topic already discussed but as I see most of them are in Chinese which I don't understand. I have difficulties in selecting the value when I use v-model and aysnc request to server for the data. The values selected are all replaced by the values from the server. If I see the log, everytime I select an option, it requests to server again. Thanks

<no-ssr placeholder="Loading...">
	<v-selectpage :data="MY_SERVER_ENDPOINT"
				  name="currency"
				  show-field="name"
				  title="Select Currency"
				  v-model="asd"
				  search-field="keyword"
				  @values="changeData"
				  :result-format="resultFormat">
	</v-selectpage>
</no-ssr>

Selectpage's v-model overrides the default value

I load data from the server and only after the data arrives, I render the v-selectpage component using v-if. The v-model of the component is bind to selected_model. At first, the selected_model is 24. However, the component overrides the selected_model to empty string.

Is this the intended behavior?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.