state.endEdit hanging in dataSourceChanged

Hello. I'm following the example which CRUD using Service class. 

CRUD works well, except processing state.endEdit and state.cancelEdit.


The grid hanged after Ajax call though call both endEdit and cancelEdit. 

I also tried call via $refs.[gridRef].ej2Instances.endEdit, but no effected.

What's the problem? How can I avoid this situation?

          <ejs-grid :dataSource="psbItems" :editSettings="editSettings" ref="psbItemGrid"
:toolbar="toolbar" @toolbarClick="toolbarClick"
:dataStateChange="dataStateChange" @dataSourceChanged="dataSourceChanged">
<e-columns>
<!-- <e-column field="cmdty.cmdtyCd" headerText="코드" width="150"></e-column>-->
<e-column field="cmdtyCd" headerText="품목"
:template="commodityTemplate" :editTemplate="commodityEditTemplate" width="300"></e-column>
<!-- <e-column field="cmdty.cmdtyCd" headerText="품목" :template="commodityTemplate" :editTemplate="commodityEditTemplate" width="300"></e-column>-->
<e-column field="sleStndrd" headerText="규격" :editTemplate="sleStndrdEditTemplate" width="80"></e-column>
<e-column field="sleUnitNm" headerText="주문단위" :editTemplate="sleUnitNmEditTemplate" width="80"></e-column>
<e-column field="minOrdQty" editType="numericedit" :edit="numericParams" headerText="최소주문수량" width="140"></e-column>
<e-column field="maxOrdQty" editType="numericedit" :edit="numericParams" headerText="최대주문수량" width="140"></e-column>
<e-column field="qtyPerOrd" editType="numericedit" :edit="numericParams" headerText="주문단위수량" width="140"></e-column>
<e-column field="prdVsblAt" headerText="기간노출여부" width="120"></e-column>
<e-column field="prdBgnDe" headerText="시작일" width="160"></e-column>
<e-column field="prdEndDe" headerText="종료일" width="160"></e-column>
</e-columns>
</ejs-grid>

/**
*
* @param {DataStateChangeEventArgs} state
*/
dataStateChange (state) {
state.data.opcgCd = this.item.opcgCd
this.psbItemService.execute(state).then(gridData => this.psbItems = gridData)
},
/**
* Problem here.
* @param {DataSourceChangedEventArgs} state
*/
dataSourceChanged (state) {
const _successfulFunc = (data) => {
console.log('Successful', data, state)
if (data.code === 0) {
console.log('Do endEdit') // logging well.
// state.endEdit() // 1. hanging
this.$refs.psbItemGrid.ej2Instances.endEdit() // 2. also hanging.
} else {
this.$toasted.error(data.msg)
console.log('Do cancelEdit')
state.cancelEdit()
}
}
const _errFunc = (err) => {
this.$toasted.error('요청 중 오류가 발생했습니다.')
console.error(err)
// action === 'add' 또는 'delete' 일 경우, cancelEdit가 적용되지 않는 문제가 있으므로 endEdit 으로 작성을 아예 취소해버린다.
if (state.action === 'edit') {
state.cancelEdit()
} else {
state.endEdit()
}
}
console.log('DataSource changed', state, state.action)
// state.rowIndex 이용
if (state.action === 'add') {
this.psbItemService.add(state).then(_successfulFunc).catch (_errFunc)
// this.psbItemService.add(state).then(() => state.endEdit())
} else if (state.action === 'edit') {
this.psbItemService.edit(state).then(_successfulFunc).catch (_errFunc)
} else if (state.requestType === 'delete') {
this.psbItemService.delete(state).then(_successfulFunc).catch (_errFunc)
} else {
console.log('on else')
}
},
// eslint-disable-next-line no-unused-vars
import { DataResult, DataStateChangeEventArgs, DataSourceChangedEventArgs } from '@syncfusion/ej2-vue-grids'
import format from 'string-format'
import axios from '../../axios'

format.extend(String.prototype, {})

/**
* Service config
* @typedef {Object} PsbItemService.Config
* @property {String} baseUri
* @property {String} createUri
* @property {String} updateUri
* @property {String} deleteUri
* @property {String} initUri
* @property {String} bulkUpdateUri
*/

class PsbItemService {
/**
*
* @param {Config} options
* @constructor
*/
constructor (options = {}) {
this.baseUri = options.baseUri
this.createUri = options.createUri
this.editUri = options.editUri
this.deleteUri = options.deleteUri
this.initUri = options.initUri
this.bulkUpdateUri = options.bulkUpdateUri
}

/**
*
* @param {String} keyString
* @param {*} keyValue
*/
setPk (keyString, keyValue) {
this.keyString = keyString
this.keyValue = keyValue
}

/**
*
* @param {DataStateChangeEventArgs} state
* @returns {Promise<DataResult>}
*/
execute (state) {
return this.getData(state)
}

/**
*
* @param {DataStateChangeEventArgs} state 페이지 정보는 where 속성의 pageNo, pageSize 로 정의한다
* @returns {Promise<DataResult>}
*/
getData (state) {
let url = this.baseUri.format(state.data)

return axios.get(url, {
params: state.where
}).then(({data}) => {
console.log(data)

return data
})
}

/**
*
* @param {DataSourceChangedEventArgs} state
* @returns {Promise<DataResult>}
*/
add (state) {
let url = this.createUri

if (this.keyString && !state.data[this.keyString]) {
state.data[this.keyString] = this.keyValue
}

return axios.post(url, state.data).then(({ data }) => {
// console.log(data)
return data
})
}

/**
*
* @param {DataSourceChangedEventArgs} state
* @returns {Promise<DataResult>}
*/
edit (state) {
let url = this.editUri
return axios.post(url, state.data).then(({ data }) => {
return data
})
}

/**
* 단건 데이터 삭제
* @param {DataSourceChangedEventArgs} state
* @returns {Promise<DataResult>}
*/
delete (state) {
if (this.keyString && !state.data[0][this.keyString]) {
state.data[this.keyString] = this.keyValue
}
let url = this.deleteUri.format(state.data[0])
return axios.post(url)
.then(({ data }) => {
return data
})
}

/**
* 데이터 초기설정
* @param {DataSourceChangedEventArgs} state
* @returns {Promise<DataResult>}
*/
init (state) {
let url = this.initUri.format(state.data)
return axios.post(url)
.then(({ data }) => {
return data
})
}

/**
*
* @param {DataSourceChangedEventArgs} state
* @returns {Promise<DataResult>}
*/
// bulkUpdate (state) {
// let url = '/priceLists/{prcListCd}/commodities/edit'.format(state.query)
//
// console.log(url)
// // return axios.post(url, state.changes)
// // .then(({ data }) => {
// // return data
// // })
// }
}

export { PsbItemService }

1 Reply 1 reply marked as answer

BS Balaji Sekar Syncfusion Team July 17, 2020 07:34 AM UTC

HI Minkyu, 
 
Greetings from the Syncfusion support. 
 
We have validated your query(custom binding) with the information provided, and we cannot reproduce the problem reported. Using Vue framework, we created a sample with custom binding in DataGrid. 
For more information please refer to the example and sample code below.  
[Vue] 
<template> 
  <div> 
    <h4 v-if="loading">Loading...</h4> 
    <ejs-grid :dataSource='gridData' :allowPaging='true' :allowSorting='true' :dataStateChange='dataStateChange' :dataSourceChanged ='dataSourceChanged ' :editSettings='editSettings' :toolbar='toolbar'> 
            <e-columns> 
                <e-column field= "orderID" headerText="Order ID" isPrimaryKey=true width="130" textAlign='Right' ></e-column> 
                <e-column field= "shipCountry" headerText="Ship City" width="150"></e-column> 
                <e-column field= "customerID" headerText="Customer Name" width="150"></e-column> 
            </e-columns> 
        </ejs-grid> 
  </div> 
</template> 

<script> 
.  .  . 
Vue.use(GridPlugin); 

  export default { 
    name: 'LinkList', 
    data () { 
      return { 
  editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
         .  .  . 
      } 
    }, 
    mounted() { 
    let state = { skip: 0, take: 4 }; 
    this.dataStateChange(state); 
  }, 
    
    methods: { 
      dataStateChange: function (state) { 
      this.$apollo.query({ 
        query: ALL_ORDERS_QUERY, 
         variables: {  
          // here we have used paging state. You can also add sorting and filtering variables 
          first: state.take, 
          skip: state.skip, 
      } 
      }).then(({ data, errors }) => { 
              this.gridData = {result:data.allOrders,count:data._allLinksMeta.count} 
          })      
    }, 

     dataSourceChanged : function (state) { 
     if (state.action === 'add') { 
        const { orderID, shipCountry, customerID } = state.data; 
         // mutation for add 
      this.$apollo.mutate({ 
            mutation: CREATE_ORDER_MUTATION, 
                 variables: { 
                     orderID, 
                     shipCountry, 
                    customerID 
                    } 
                  }).then(({ data, errors }) => { state.endEdit()}); 

    } else if (state.action === 'edit') { 
              const { id,orderID, shipCountry, customerID } = state.data; 
       // mutation for edit 
      this.$apollo.mutate({ 
             mutation: UPDATE_ORDER_MUTATION, 
                 variables: { 
                      id, 
                     orderID, 
                     shipCountry, 
                    customerID 
                    } 
                  }).then(({ data, errors }) => { state.endEdit()}); 

    } else if (state.requestType === 'delete') { 
       const { id } = state.data[0]; 
       // mutation for delete 
      this.$apollo.mutate({ 
             mutation: DELETE_ORDER_MUTATION, 
                 variables: { 
                      id 
                    } 
                  }).then(({ data, errors }) => { state.endEdit()}); 
    }     
    }, 
    }, 
    provide: { 
      grid: [Sort, Page, Edit, Toolbar] 
  } 
  } 
</script> 

 
 
If you have the same problem , please replicate the problem in the above sample and share it with us to help further validate. 
 
Regards, 
Balaji Sekar 


Marked as answer
Loader.
Up arrow icon