204 lines
5.5 KiB
Vue
204 lines
5.5 KiB
Vue
<template>
|
|
<div>
|
|
<h3 class="content-block main-title">Instansi</h3>
|
|
<p class="content-block">Instansi</p>
|
|
<div class="content-block">
|
|
<div class="dx-card responsive-paddings">
|
|
<div id="app-container">
|
|
<DxDataGrid ref="currDataGrid"
|
|
:data-source="customDataSource"
|
|
key-expr="id"
|
|
@editing-start="onEditingStart"
|
|
@saving="onSaving"
|
|
:allow-column-reordering="true"
|
|
:column-auto-width="true">
|
|
<DxRemoteOperations :group-paging="true" />
|
|
<DxEditing
|
|
:allow-adding="true"
|
|
:allow-updating="true"
|
|
:allow-deleting="true"
|
|
:use-icons="true"
|
|
form="popup"
|
|
mode="popup">
|
|
<DxTexts
|
|
add-row="Tambah"
|
|
edit-row="Ubah"
|
|
delete-row="Hapus"
|
|
confirm-delete-message="Apakah anda yakin untuk menghapus data ini?"
|
|
save-row-changes="Simpan"
|
|
cancel-row-changes="Batal"
|
|
></DxTexts>
|
|
<DxForm label-location="top" :col-count="1">
|
|
<DxItem dataField="instansi">
|
|
<DxRequiredRule message="Instansi harus diisi" />
|
|
</DxItem>
|
|
<DxItem dataField="alamat"/>
|
|
<DxItem dataField="keterangan" />
|
|
</DxForm>
|
|
<DxPopup
|
|
:hide-on-outside-click="true"
|
|
:show-title="true"
|
|
:width="400"
|
|
:height="400"
|
|
title="Form Instansi"
|
|
/>
|
|
</DxEditing>
|
|
<DxToolbar>
|
|
<DxItem name="groupPanel" />
|
|
<DxItem name="searchPanel" location="before"/>
|
|
<DxItem name="addRowButton" show-text="always" css-class="">
|
|
<DxTexts add-row="Tambah"></DxTexts>
|
|
</DxItem>
|
|
<DxItem name="exportButton" />
|
|
<DxItem name="columnChooserButton" />
|
|
</DxToolbar>
|
|
<DxPaging :page-size="5" />
|
|
<DxPager
|
|
:visible="true"
|
|
:allowed-page-sizes="[5, 10, 50]"
|
|
display-mode="compact"
|
|
:show-page-size-selector="true"
|
|
:show-info="true"
|
|
:show-navigation-buttons="true"
|
|
info-text="Hal {0} dari {1} ({2} data)" />
|
|
<DxFilterRow :visible="false" />
|
|
<DxColumn data-field="id" caption="No" :width="45"></DxColumn>
|
|
<DxColumn data-field="instansi" caption="Instansi"></DxColumn>
|
|
<DxColumn data-field="alamat" caption="Alamat"></DxColumn>
|
|
<DxColumn data-field="keterangan" caption="Keterangan"></DxColumn>
|
|
<DxColumn type="buttons" caption="Aksi">
|
|
<DxButton name="edit"/>
|
|
<DxButton name="delete"/>
|
|
</DxColumn>
|
|
<DxSearchPanel :visible="true" :highlight-case-sensitive="true" :width="300" placeholder="Cari Instansi..."/>
|
|
<!--<DxExport
|
|
:enabled="true"
|
|
:formats="['xlsx', 'pdf']"
|
|
:allow-export-selected-data="true"
|
|
/>-->
|
|
</DxDataGrid>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import DxDataGrid, {
|
|
DxEditing,
|
|
DxItem,
|
|
DxForm,
|
|
DxPopup,
|
|
DxColumn,
|
|
DxFilterRow,
|
|
DxPager,
|
|
DxPaging,
|
|
DxSearchPanel,
|
|
DxToolbar,
|
|
DxTexts,
|
|
DxRequiredRule
|
|
} from "devextreme-vue/data-grid";
|
|
import CustomStore from "devextreme/data/custom_store";
|
|
|
|
const URL = process.env.VUE_APP_ROOT_API+'/instansi';
|
|
|
|
const customDataSource = new CustomStore({
|
|
key: 'id',
|
|
|
|
load: () => {
|
|
return fetch(URL+process.env.VUE_APP_PAGE_SIZE)
|
|
.then((response) => response.json())
|
|
.catch(() => { throw new Error('Terdapat kesalahan memuat data'); });
|
|
},
|
|
|
|
insert: (values) => {
|
|
return fetch(URL, {
|
|
method: "POST",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
},
|
|
|
|
update: (key, values) => {
|
|
return fetch(URL + "/" + encodeURIComponent(key), {
|
|
method: "PUT",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
},
|
|
|
|
remove: (key) => {
|
|
return fetch(URL + "/" + encodeURIComponent(key), {
|
|
method: "DELETE",
|
|
});
|
|
},
|
|
});
|
|
|
|
export default {
|
|
components: {
|
|
DxDataGrid,
|
|
DxEditing,
|
|
DxItem,
|
|
DxForm,
|
|
DxPopup,
|
|
DxColumn,
|
|
DxFilterRow,
|
|
DxPager,
|
|
DxPaging,
|
|
DxSearchPanel,
|
|
DxToolbar,
|
|
DxTexts,
|
|
DxRequiredRule
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
//jsonUrl: URL,
|
|
customDataSource,
|
|
rowEdit: {
|
|
id: null,
|
|
alamat: '',
|
|
instansi: '',
|
|
isDelete: false,
|
|
keterangan: ''
|
|
},
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
|
|
onEditingStart(e) {
|
|
this.rowEdit = e.data;
|
|
},
|
|
|
|
async onSaving(e) {
|
|
const isCanceled = new Promise((resolve) => {
|
|
|
|
const data = Object.assign(this.rowEdit, e.changes[0].data);
|
|
|
|
fetch(`${URL}/${data.id}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify(data),
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
})
|
|
.then(() => resolve(false));
|
|
|
|
resolve(true);
|
|
});
|
|
|
|
e.cancel = isCanceled;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
</style>
|