Textarea and select values are lost after updating datatable

Textarea and select values are lost after updating datatable

auto_reportsauto_reports Posts: 8Questions: 3Answers: 0

I have a on change event attached to my dataTable which seems to update the dataTable correctly but in the front end, the dropdown value is always set to the first option no matter what option is selected. What am I doing wrong? On change seems to work fine for input. For textarea as well (comments box), the value does not seem to hold.

If I remove on change function, then the front end works just fine (The dropdown option is selected correctly). However, the datatable is not updated. So I need the on change function. Here is the fiddle https://jsfiddle.net/cyzpv42o/3/

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 13,817Questions: 25Answers: 3,253
    Answer ✓

    Looks like you are using textarea incorrectly. According to the textarea docs:

    Default content entered between the opening and closing tags. <textarea> does not support the value attribute.

    You need to do something like return "<textarea rows='4' cols='80'>" + ditem + "</textarea>" ; instead of using the value attribute. Like this:
    https://jsfiddle.net/qy6t3s8w/

    Kevin

  • auto_reportsauto_reports Posts: 8Questions: 3Answers: 0

    Thanks @kthorngren . Looks like this solves the problem with Textarea. Any clues about select?

  • kthorngrenkthorngren Posts: 13,817Questions: 25Answers: 3,253

    Your data for the select column is an empty string. I changed it to Yes and changed the use of val() to use the column data, for example: $("#eligible_1st_" + a).val(data);.
    https://jsfiddle.net/vk0fdmax/1/

    Not sure this is working as you expect:

    var a = result.indexOf(row);
    

    The row parameter is the full row data. Maybe you want to row index which you can get from the meta parameter, for example meta.row. See the columns.render docs for more details.

    Kevin

Sign In or Register to comment.