vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.67k stars 727 forks source link

selected in request is empty #1761

Open swanrnd opened 6 years ago

swanrnd commented 6 years ago

Hi, I've a problem. I use this project for dynamic and big tables. I need to save a postion after a partly reload. But field selected is empty always: request: {"cmd":"get","selected":[],"limit":100,"offset":0}. It's very important information for my server. How can I solve this problem?

mpf82 commented 6 years ago

The "problem" is, that reload calls clear, which also clears the current selection.

Fortunately, it also calls selectionSave, so you can use this work-around:

grid.onRequest = function(event) {
    event.postData.selected = this.last._selection ? this.last._selection : this.getSelection();
};

Side note: personally, I can't think of a use-case, where the server must know the last selection, when you reload the data, and the front-end (w2grid) does restore the last selection. Unless you're using the tree mode and you're modifying the record's expand properties based on the selection.

Care to share your use-case?

Cheers =)

swanrnd commented 6 years ago

Okay. About my case. We have a big table with 1000+ records. It's dynamic data. Sometimes we have new rows or without old rows. Sometimes ceil change. Operator fixs one row and track it It can be 1500th from 10 000. And we have to reload data without reload all dates. We use script for reloading and repaint rows. Recid is a position in the table. We change all changed rows and remove rest or add rest. After sorting selected recid=1 become recid=1000.

I want to do 2 things 1) send the current selected postion with sorting or searching. I can't to send current select to server. 2) send the curren selected postion with our updating. I can change params of my query.

Now I thing about solution.