is there an onselect event in the select extension

is there an onselect event in the select extension

izumovizumov Posts: 178Questions: 14Answers: 0

is there an onselect event in the select extension that occurs when I select a row? I need to handle this event

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918

    Here are the select events:
    https://datatables.net/reference/event/#select

    Depending on your needs you will want either select or user-select.

    Kevin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    Please see my code I have why the handler does not work when you select a line
    $('#orders').on( 'select', function ( e, dt, type, indexes ) {
    if ( type === 'row' ) {
    kod=table.rows( {selected:true} ).data();
    kodorder=kod[0][0];
    alert('orders kod is:'+kodorder);
    }
    });

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918

    What exactly is not working?

    I think this is incorrect $('#orders').on(. Try $('#orders').DataTable().on( to get an API instance.

    If this doesn't help then please post a link to your page or a test case so we can see what you have.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    @izumov : please can you only put the triple-back ticks before the first line of code, and after the final line of code - not on every line. Thanks.

  • izumovizumov Posts: 178Questions: 14Answers: 0

    why wasn't my question posted yesterday?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    ?

  • izumovizumov Posts: 178Questions: 14Answers: 0
    edited June 2019

    I asked how to access the first column of the selected row in the handler because my code was not functional .My cod:

        $('#orders').DataTable().on( 'select', function ( e, dt, type, indexes ) {
        if ( type === 'row' ) {
            kod= table.rows( indexes ).data()
     var data = table.rows( indexes ).data().pluck( 'kod' );
            kodorder=kod[0][0];
            alert('orders kod is::'+kodorder);
        }
        });
    
  • izumovizumov Posts: 178Questions: 14Answers: 0

    This is a row that is only is selecting and at the time of the handler's operation as far as I understand is not selected

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    Here is my test case
    http://montaj.vianor-konakovo.ru/orders024.html
    An error occurs when you select a row
    Cannot read property '0' of undefined

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    It's because you haven't defined table - if you change table to be dt (it's provided in the callback) on lines 3 and 4 above, everything works fine.

  • izumovizumov Posts: 178Questions: 14Answers: 0

    Thanks for the hint now the code works correctly.

This discussion has been closed.