bootstrap-sortable icon indicating copy to clipboard operation
bootstrap-sortable copied to clipboard

Alter TD value and re-sort, doesn't work.

Open marcreig opened this issue 8 years ago • 3 comments

Hi again. Last changes made my day. Them taken a long time, but already done! So thanks again.

Now about this feature:

  • I've a table, with normal TDs with some content on'em, text and numbers. Content is inside an <span>.
  • I've created a JS snipet which on TD-content click, it changes from span to input-text, and let's you alter the content. On blur then, it saves changes on DB, and comes back from input-text to span. Quite tipical nowadays.

Expecting a behaviour like the one exposed on info text:

When you add table rows or whole table from client side, use $.bootstrapSortable({ applyLast: true }) function to add sortability to parts/tables that were not present at document.ready. Use optional paramater applyLast=true if you want to preserve the last used sorting.

I've called the $.bootstrapSortable({applyLast: true, sign: 'reversed'});

But nothing happens. Do not re-sorts the changed row. So to solve this, I've basically added an snippet on my "from input-text to span" part, which changes the "data-value" from the span parent TD. And after that, I call the $.bootstrapSortable({applyLast: true, sign: 'reversed'}); and then it works.

$(this).parents('td').attr("data-value", $(this).val().toUpperCase()); //fill data-value to re-sort on change.

Question is: is this the normal behaviour? Or it is expected to re-map the TD "data-value" automatically when $.bootstrapSortable({applyLast: true, sign: 'reversed'}); is called?

Thanks and kind regards.

marcreig avatar Nov 24 '16 17:11 marcreig

in this case you are not adding new row, you are just changing content of the cell, but the cell has already set the data-value attribute from the previous state

your solution is fine

drvic10k avatar Nov 25 '16 21:11 drvic10k

that's exactly my case. you change content of the cell. but cell has already data-value attributes from previous state. this destroys sorting by clicking headers also. if it's by design probably specify this in documentation? that if you change cell value what you should do? or call bootstrapTable() again. or set data value attribute. is I understand not always will work because you use moment.js on datavalue attribute. probably add method "setCell()" that will set attribute hiding details of implementation from user? thanks in advance )

bergano65 avatar Nov 28 '16 12:11 bergano65

unfortunately the same attribute is used to predefine the data-value in markup and also to fill the values by plugin possible solution would be to use separate attributes for predefined values, I will keep this as a possible improvement

drvic10k avatar Mar 26 '17 19:03 drvic10k