Events lost after setting cell value or redraw

Events lost after setting cell value or redraw

aglachantaglachant Posts: 4Questions: 0Answers: 0
edited May 2014 in DataTables 1.10

Hi,

after many hours losts to find why my scripts doesn't work properly, i need your help.

The context is the following :
- I create many datatables ' on the same page
- the user can add / delete rows dynamicaly
- the rows contains inputs with jquery objects as datepicker (http://bootstrap-datepicker.readthedocs.org/en/latest/methods.html), and events attached on them...
- after modyfying inputs val, a function is called to resort datatable on hidden column (whichone is updated with user value but shawn in the fiddle below)

the problem is that after user changes cells values (or redrawing ?) :

input doesn't memorize value, datepickers are losts, events are losts (only on rows added dynamicaly);
sorting behavior on columns seems to be 'fanciful' (sort seems to be active only on initial rows)

...but maybe i am doing something wrong...

I thought to reinitialize objects by draw Callback but intial rows (no added by users) keep events OK so i think it's not a good alternative...

as my javascript is very 'heavy', i select only interesting parts to show you my code and hope you can help me to solve problem (disabling validation add rules ..),

JS FIDDLE here showing the problem (try to add row on "+ green button" and modyfing : http://jsfiddle.net/aglachant/Fm2z9/

THANKS for your help,
best regards
Alex

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You are using static events. See the top FAQ: http://datatables.net/faqs/#events .

    Allan

  • aglachantaglachant Posts: 4Questions: 0Answers: 0

    Sorry, i don't undestand your answer, i use event as in the example :
    Example :
    $('#example tbody').on('click', 'tr', function () {
    var name = $('td', this).eq(0).text();
    alert( 'You clicked on '+name+'\'s row' );
    } );

    In my script :
    $('#'+table_id).on('blur', '#pri_'+id, function (){
    var table = $(this).closest('table').DataTable();
    table.cell( $(this).closest('tr').find('td:first') ).data( $(this).val() ).draw();
    table.order( [ 1, 'asc' ] ).draw();
    });

    In my case, value written by user is lost...

    Otherwise, how should i set objects as datepicker ? it seems i don't take the good way...

    thanks for your help !

  • aglachantaglachant Posts: 4Questions: 0Answers: 0
    edited May 2014

    8 hours more on it ...can't find any solution ...pleaasse heellp !!! ;)

  • aglachantaglachant Posts: 4Questions: 0Answers: 0

    i tryed to create my own plugin et got same problems...finaly i found problem and solution, i used jquery validation on the same page and problem came from jquery detach() method...

    this one get out inputs from the context whith bad approach, it seems it's the same problem with Datatables "order method" (or draw..).

    Thanks 4 your help

This discussion has been closed.