一个简单的样式和强大的选择器,包括 Ajax 远程数据、自动完成、分页、标签、i18n 和键盘导航功能
A simple style and powerful selection jQuery plugin, including ajax remote data, autocomplete, pagination, tags, i18n and keyboard navigation features
Explorer on
The Vuejs version: v-selectpage
| IE / Edge | Firefox | Chrome | Safari | Opera |
|---|---|---|---|---|
| IE8, IE9, IE10, IE11, Edge | Firefox 18+ | Chrome 49+ | Safari 10+ | Opera 36+ |
Multiple Selection with Tags form
Regular select mode ( single selection )
List only ( pagination bar close, disable typing to quick search, select only )
Download SelectPage plugin zip file by last release, or click me to download SelectPage
or use NPM
npm install selectpageAs you can see in the Demo Page, you will need to include:
selectpage.js (or its minified version selectpage.min.js)selectpage.cssthe SelectPage plugin just need put a input tag in the page
// defined a array (the server side returned data format was same like that)
// Array[{Object},{...}]
var data = [
{id: 1, name: 'Chicago Bulls', desc: '芝加哥公牛' },
{id: 2, name: 'Cleveland Cavaliers', desc: '克里夫兰骑士' },
{id: 3, name: 'Detroit Pistons', desc: '底特律活塞' },
{id: 4, name: 'Indiana Pacers', desc: '印第安纳步行者' }
]
// init SelectPage
$('#selectpage').selectPage({
showField : 'desc',
keyField : 'id',
data : data
})The plugin initialize options
string | objectundefineddata source (string:ajax search URL | object:JSON format array)
// serverside request url address
$('#selectpage').selectPage({
data: 'https://some-site/some-route'
})
// JSON format array
var data = [{a:1,b:2,c:3},{...}]
$('#selectpage').selectPage({
data: data
})string'cn'plugin language
| code | language |
|---|---|
| cn | chinese |
| en | english |
| de | german |
| es | spanish |
| ja | japanse |
| pt-br | Brazilian Portuguese |
booleanfalsewhether it is multi-select mode(use tags mode)
booleantruepaging or not
number10the list shows the number of items, and the other items are displayed in a scroll bar,it only work on pagination : false
booleantruewhether to enable the multi-select mode control button area,only work on multiple: true
number0maximum number of selections in multi-select mode,0 is unlimited
booleantrueis close list after item select,it only work on multiple:true
stringundefinedthe initial value of the plugin, The value will match the option.keyField field, and if it matches, it will be automatically selected and highlighted
string'tbl'use this parameter to set the corresponding data table name in server side(ajax) mode
string'id'value field, usually the contents of the field will be automatically saved in the hidden domain
string'name'the result is used to display the name of the attribute
stringundefinedquery field, set server side query field when data source is server side mode, if not set default use of option.showField
string'AND'multiple keywords search type ('AND' or 'OR')
string[]undefinedresult data sort type, default use showField specified field
$('#selectpage').selectPage({
...
orderBy : ['id desc'] // use id field sort desc
})number10the number of records per page
function (): objectobjectundefinedsend request params for server side data source(ajax)
$('#selectpage').selectPage({
...
params : function() {
return {
name: 'aa',
sex: 1
}
}
})function (data: object): stringobject row data object formatstringundefinedlist item display content formatting
$('#selectpage').selectPage({
...
formatItem : function(data) {
return data.a + '(' + data.b + ')'
}
})booleantruewhen input box get focus,drop the list
booleantruewhether to automatically select the first item in the list (enter the keyword query mode, use the mouse directly does not trigger)
booleantruewhether to automatically fill the content, if the list item is highlighted, in the focus away from the control, automatically set the item for the selected content
booleantrueenter the keyword to query and no item match,when focus leave plugin,whether to clear enter keywords
booleanfalseselect only mode,the input box can not enter any word
number0.5(second)enter the keyword query delay, work on server side(ajax) mode
function (data: object|object[]): voidobject | array selected row or rows data(json)undefineditem selected callback
$('#selectpage').selectPage({
...
eSelect : function(data) {
console.log(data)
}
})function (self: object): voidobject plugin inner objectundefinedbefore show up result list callback
$('#selectpage').selectPage({
...
eOpen : function(self) {
console.log(self)
}
})function (data: object): objectobject server side return data(json)object convert to SelectPage required data formatundefinedin server side mode, this is the callback function when request success, the role of the callback is used to custom processing of the return data
server side return data for example
{
"values": {
"gridResult": {
"pageSize": 10,
"pageNumber": 1,
"totalRow": 11,
"totalPage": 2,
"listData": [
{ "name": "name1", "id": "1" },
{ "name": "name2", "id": "2" },
{ ... }
]
}
}
}eAjaxSuccess required data format
{
list: object[], // rows data
totalRow: number // total record count number
}then eAjaxSuccess code for example below
$('#selectpage').selectPage({
...
data: 'https://some-site/some-route',
eAjaxSuccess : function(data) {
var dataNode = data.values.gridResult
return {
list : dataNode.listData,
totalRow : dataNode.totalRow
}
}
})function (tags: object[]): voidobject[] removed tags raw dataundefinedthis callback function is used to close tag, when multiple : true
$('#selectpage').selectPage({
...
eTagRemove : function(tags) {
console.log(tags)
}
})selectPageClear(): voidclear all select items
$('#selectpage').selectPageClear()selectPageRefresh(): voidrefresh plugin selected items info
$('#selectpage').val(20) // modify selected by id used javascript
$('#selectpage').selectPageRefresh() // refresh selection item infoselectPageData(data: object): voidarray new data, the data format is same to plugin data sourcechange plugin data source,only work on json data source mode
var newdata = [
{ a: 1, b: 11, c: 111 },
{ a: 2, b: 22, c: 222 },
{ ... }
]
$('#selectpage').selectPageData(newdata)selectPageDisabled(status?: boolean): void|booleanboolean(optional) set disabled stauts. true to disabled, false to enabledboolean(optional) plugin disabled statusget plugin disabled status or set plugin status to disabled / enabled
// get plugin disabled stuats
if($('#selectpage').selectPageDisabled()) {
// set plugin to enabled
$('#selectpage').selectPageDisabled(false)
}selectPageText(): stringstring selected items string contentget plugin selected items text
alert($('#selectpage').selectPageText())selectPageSelectedData(): object[]object[] selected items raw datasget selected items raw data
console.log($('#selectpage').selectPageSelectedData())暂无开放 Issues,或尚未同步最近议题。