Hi every one,
I am write a remote data multi-select
with the infinite scrolling feature.
This component can read data from API, but it can not read this data from a pagination API.
How can i write a remote data multi-select by using a pagination API?
Thank you
This is my code for reading data from API (without pagination):
<template>
<div>
<div class="control-section multiselect-databinding">
<div id='remote' style="margin: 0px auto; width:64%; padding-top: 20px;">
<h4>Remote Data</h4>
<ejs-multiselect
id="remoteData"
ref="multiselect"
:dataSource="data"
:open="onOpen.bind()"
:fields="remoteFields"
:query="query"
:placeholder="remoteWaterMark"
popupHeight="200px">
</ejs-multiselect>
</div>
</div>
</div>
</template>
<style scoped>
</style>
<script>
import Vue from "vue";
import { MultiSelectPlugin } from "@syncfusion/ej2-vue-dropdowns";
import { CheckBoxPlugin } from "@syncfusion/ej2-vue-buttons";
import { Query, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data';
Vue.use(MultiSelectPlugin);
Vue.use(CheckBoxPlugin);
let remoteData = new DataManager({
url: 'http://localhost.test/api/datasource',
adaptor: new ODataV4Adaptor,
crossDomain: true
});
export default Vue.extend ({
data: function() {
return {
data: remoteData,
remoteFields: { text: 'description', value: 'id' },
query: new Query().select(['description', 'id']).take(10).requiresCount(),
remoteWaterMark: 'Select names',
};
},
methods: {
onOpen: function (e) {
let listObj = this.$refs.multiselect.ej2Instances
let operator = new Query()
let start = 7
let end = 12
let listElement = listObj.list
listElement.addEventListener("scroll", () => {
if (listElement.scrollTop + listElement.offsetHeight >= listElement.scrollHeight) {
let filterQuery = operator.clone()
this.data
.executeQuery(filterQuery.range(start, end))
.then((event) => {
start = end
end += 5
listObj.addItem(event.result)
})
.catch((e) => {})
}
})
},
},
});
</script>
This is a page of pagination API: http://localhost.test/api/datasource?page=
{
"current_page": 1,
"data": [
{
"id": 1,
"description": "...",
},
{
"id": 2,
"description": "...",
},
{
"id": 3,
"description": "...",
},
{
"id": 4,
"description": "...",
},
{
"id": 5,
"description": "...",
}
],
"first_page_url": "http://localhost.test/api/datasource?page=1",
"from": 1,
"last_page": 20,
"last_page_url": "http://localhost.test/api/datasource?page=20",
"links": [
{ "url": null, "label": "« Previous", "active": false },
{ "url": "http://localhost.test/api/datasource?page=1", "label": "1", "active": true },
{ "url": "http://localhost.test/api/datasource?page=2", "label": "2", "active": false },
{ "url": "http://localhost.test/api/datasource?page=3", "label": "3", "active": false },
{ "url": "http://localhost.test/api/datasource?page=4", "label": "4", "active": false },
{ "url": "http://localhost.test/api/datasource?page=5", "label": "5", "active": false },
{ "url": "http://localhost.test/api/datasource?page=6", "label": "6", "active": false },
{ "url": "http://localhost.test/api/datasource?page=7", "label": "7", "active": false },
{ "url": "http://localhost.test/api/datasource?page=8", "label": "8", "active": false },
{ "url": "http://localhost.test/api/datasource?page=9", "label": "9", "active": false },
{ "url": "http://localhost.test/api/datasource?page=10", "label": "10", "active": false },
{ "url": null, "label": "...", "active": false },
{ "url": "http://localhost.test/api/datasource?page=19", "label": "19", "active": false },
{ "url": "http://localhost.test/api/datasource?page=20", "label": "20", "active": false },
{ "url": "http://localhost.test/api/datasource?page=2", "label": "Next »", "active": false }
],
"next_page_url": "http://localhost.test/api/datasource?page=2",
"path": "http://localhost.test/api/datasource",
"per_page": 5,
"prev_page_url": null,
"to": 5,
"total": 100
}