muhimasri / b-editable-table

A Bootstrap Vue editable table for editing cells using built-in Bootstrap form elements
MIT License
33 stars 11 forks source link

rest API update data #19

Closed zms2003 closed 2 years ago

zms2003 commented 2 years ago

Hello. How I can update data by restAPI fron this component? When I take a handler input-change, handler is working on any symbol what I press. How I can use b-editable-table whith update by restAPI?

handleInput(value, data) { this.users_table_busy=true const payload={ id: data.item.id, field:data.field.value, value:value } this.$store.dispatch('user_actons/UPDATE_USER', payload).then( data => { this.message = data.message; this.successful = true; if (this.message=="success"){ this.$store.dispatch('user_actons/GET_USERSLIST', ).then( res=>{ console.log(res) this.items = this.$store.getters['user_actons/USERS_LIST'] }).catch(err=>{ throw err }) } }, error => { this.message = (error.response && error.response.data && error.response.data.message) || error.message || error.toString(); this.successful = false; } ); this.users_table_busy=false }

muhimasri commented 2 years ago

Hi @zms2003 , thanks for opening an issue.

I am aware that the @input-change event triggers on every keypress. I'm currently working on new enhancements that include changes in input events; @change will trigger only when changing and leaving the input field, and @input trigger on keypress. I believe that will solve the issue that you are facing.

I will release the latest changes in the coming two days. So please stay tuned, and I will notify you as soon as it's up and running! If you need to get something working now, consider using a debounce function so your API does not trigger on every keypress. https://stackoverflow.com/questions/42199956/how-to-implement-debounce-in-vue2

Also, new changes will include a row update option. Meaning you can use an external button to update specific rows. That will be more efficient for API calls as you only trigger an update when clicking on a "save" button.

Lastly, I noticed that you are getting the field name "field:data.field.value," it should be "field:data.field.key" instead.

Cheers, Muhi

zms2003 commented 2 years ago

Thank you very much

muhimasri commented 2 years ago

Hi @zms2003 ,

The latest changes has been deployed. Please update your package with latest version "0.1.2-beta.4".

There are two breaking changes:

  1. Every row requires a unique id, which I believe you're already doing.
  2. @input-change event will trigger on change only and when leaving the input rather than on keypress. Also, the argument of the event handler now has only one object containing all the information including the value and id of the current row/field.

Please look at the updated examples below on Codesandbox and let me know if there are any issues as we're trying to have a stable version of b-editable-table component

Edit Cell | Edit Row | Add, Update and Remove Rows | Load Data via Rest API

zms2003 commented 2 years ago

Thank you very much. I'll testing your package tomorrow

zms2003 commented 2 years ago

Hello, [muhimasri] ;) new little issue.. when i set editable cell type=date, and row is bottom of screen, select date dialog is out of screen

muhimasri commented 2 years ago

Thanks @zms2003 for testing and pointing out the issue. This is very helpful :)

I will create a separate issue for "date dialog not being visible at the bottom of the page" and will add a fix in this week's release.

If the REST API update is not a problem for you anymore, we can close this issue.