Skip to content

Transfer

Rules

Basic Example

js
const rule = {
    type:"aTransfer",
    title:"Transfer",
    field:"transfer",
    modelField:"selectedKeys",
    value:[],
    props:{
        titles:['Source', 'Target'],
        render: (item) => item.label,
        dataSource:[{
            value: 'beijing',
            label: 'Beijing',
            children: [
                {
                    value: 'gugong',
                    label: 'Forbidden City'
                },
                {
                    value: 'tiantan',
                    label: 'Temple of Heaven'
                },
                {
                    value: 'wangfujing',
                    label: 'Wangfujing'
                }
            ]
        }, {
            value: 'jiangsu',
            label: 'Jiangsu',
            children: [
                {
                    value: 'nanjing',
                    label: 'Nanjing',
                    children: [
                        {
                            value: 'fuzimiao',
                            label: 'Confucius Temple',
                        }
                    ]
                },
                {
                    value: 'suzhou',
                    label: 'Suzhou',
                    children: [
                        {
                            value: 'zhuozhengyuan',
                            label: 'Humble Administrator\'s Garden',
                        },
                        {
                            value: 'shizilin',
                            label: 'Lion Grove Garden',
                        }
                    ]
                }
            ]
        }]
    }
}

Props Configuration Examples

Searchable

js
const rule = {
    type:"aTransfer",
    title:"User Selection",
    field:"users",
    modelField:"selectedKeys",
    value:[],
    props:{
        titles:['Available Users', 'Selected Users'],
        dataSource:[
            {value: '1', label: 'Zhang San'},
            {value: '2', label: 'Li Si'},
            {value: '3', label: 'Wang Wu'},
        ],
        showSearch: true,
        render: (item) => item.label,
    },
}

Custom Titles and Buttons

js
const rule = {
    type:"aTransfer",
    title:"Permission Assignment",
    field:"permissions",
    modelField:"selectedKeys",
    value:[],
    props:{
        titles:['Available Permissions', 'Selected Permissions'],
        operations: ['Add', 'Remove'],
        dataSource:[
            {value: 'view', label: 'View'},
            {value: 'edit', label: 'Edit'},
            {value: 'delete', label: 'Delete'},
        ],
        render: (item) => item.label,
    },
}

Events Examples

Listen to Selection Changes

js
const rule = {
    type:"aTransfer",
    title:"User Selection",
    field:"users",
    modelField:"selectedKeys",
    value:[],
    props:{
        dataSource:[
            {value: '1', label: 'Zhang San'},
            {value: '2', label: 'Li Si'},
        ],
        render: (item) => item.label,
    },
    on: {
        change: (targetKeys, direction, moveKeys) => {
            console.log('Right list changed:', targetKeys);
            console.log('Move direction:', direction);
            console.log('Moved keys:', moveKeys);
        },
        search: (direction, value) => {
            console.log('Search:', direction, value);
        },
    },
}

Count After Selection

js
const rule = [
    {
        type:"aTransfer",
        title:"User Selection",
        field:"users",
        modelField:"selectedKeys",
        value:[],
        props:{
            dataSource:[
                {value: '1', label: 'Zhang San'},
                {value: '2', label: 'Li Si'},
                {value: '3', label: 'Wang Wu'},
            ],
            render: (item) => item.label,
        },
        inject: true,
        on: {
            change: ($inject, targetKeys) => {
                // Automatically update selected count
                $inject.api.setValue('selectedCount', targetKeys.length);
            },
        },
    },
    {
        type:"input-number",
        field:"selectedCount",
        title:"Selected Count",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: Ant-design-vue_Transfer

Props

ParameterDescriptionTypeDefault
dataSourceData source, data in it will be rendered to left column, except those specified in targetKeys.[{key: string.isRequired,title: string.isRequired,description: string,disabled: bool}][][]
disabledWhether disabledbooleanfalse
filterOptionReceives inputValue and option as parameters. When option meets filter condition, should return true, otherwise return false.(inputValue, option): boolean
footerCan be set to a scoped slotslot="footer" slot-scope="props"
listStyleCustom styles for two transfer boxesCSSProperties
localeVarious languagesobject{ itemUnit: 'item', itemsUnit: 'items', notFoundContent: 'List is empty', searchPlaceholder: 'Search' }
oneWayDisplay as one-way stylebooleanfalse
operationsCollection of operation text, order from top to bottomstring[]['>', '<']
operationStyleCustom style for operation barCSSProperties-
paginationUse pagination style, invalid when custom rendering listboolean | { pageSize: number, simple: boolean, showSizeChanger?: boolean, showLessItems?: boolean }flase
renderRender function for each row of data, parameter is item in dataSource, return value is element. Or return a plain object, where label field is element, value field is titleFunction(record)| slot
selectAllLabelsCollection of custom titles for top checkboxesVueNode | ((info: { selectedCount: number; totalCount: number }) => VueNode)-
selectedKeys(v-model)Set which items should be selectedstring[][]
showSearchWhether to show search boxbooleanfalse
showSelectAllWhether to show select all checkboxbooleantrue
statusSet validation status'error' | 'warning'-
targetKeys(v-model)Collection of keys for data displayed in right boxstring[][]
titlesCollection of titles, order from left to rightstring[]['', '']

Events

Event NameDescriptionCallback Parameters
changeCallback function when options transfer between two columns(targetKeys, direction, moveKeys): void
scrollCallback function when option list scrolls(direction, event): void
searchCallback function when search box content changes(direction: 'left'|'right', value: string): void
selectChangeCallback function when selected items change(sourceSelectedKeys, targetSelectedKeys): void

Render Props

Transfer supports receiving children to custom render list, and returns the following parameters:

json
{
  "direction": String,
  "disabled": Boolean,
  "filteredItems": Array,
  "selectedKeys": Array,
  "onItemSelect": Function,
  "onItemSelectAll": Function
}
ParameterDescriptionType
directionDirection of rendered list'left' | 'right'
disabledWhether list is disabledboolean
filteredItemsFiltered dataTransferItem[]
itemSelectSelect item(key: string, selected: boolean)
itemSelectAllSelect a group of items(keys: string[], selected: boolean)
selectedKeysSelected itemsstring[]

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.