Can't get value of selected row with select plugin

Can't get value of selected row with select plugin

scotexscotex Posts: 3Questions: 1Answers: 0

Hi,

I'm creating and populating my table as follow

$('#tableArtikel').DataTable().destroy();
        table = $('#tableArtikel').DataTable({
            "processing": true,
            "pageLength": 5,
            "lengthChange": false,
            "select": {
                'style': 'single'
            },
            "ajax": {
                "url": "@Url.Action("OmschrijvingFilter", "App")?id=" + $('#omschrijving').val(),
                dataSrc: ''
            },
            "columns": [{
                "data": "artikelnummmer"
            }, {
                "data": "omschrijving"
                }],
            'columnDefs': [
                {
                    'width': 25,
                    'targets': 0
                }],
            'fixedColumns': true,
            'order': [[0, 'asc']]
        });

And I'm trying to get the value of first column from the selected row

I've tried following

table = $('#tableArtikel').DataTable();
        var data = table.row({ selected: true }).data();
table = $('#tableArtikel').DataTable();
        var data = table.row({ selected: true }).data()[0];
table = $('#tableArtikel').DataTable();
        var data = table.row({ selected: true }).data.Nummer;
table = $('#tableArtikel').DataTable();
        var data = table.row({ selected: true }).data()['Nummer'];
table = $('#tableArtikel').DataTable();
        var data = table.row('.selected').data();

What am I doing wrong?

Thanks

Answers

  • scotexscotex Posts: 3Questions: 1Answers: 0

    Json format of my data is following

    [
        {
            "artikelnummmer": "I009295",
            "omschrijving": "BPTPNP-01-434/7564-0,5 | PRINT & PROTECT 20X30MM TTP"
        },
        {
            "artikelnummmer": "I018477",
            "omschrijving": "BPTPNP-01-483/7552-0,5/1GR PRE PRINTED PRINT&PROTECT 20X30MM"
        },
        {
            "artikelnummmer": "I010016",
            "omschrijving": "BPTPNP-016X030-434/7552-0,5 | PRINT&PROTECT 16X30MM"
        },
        {
            "artikelnummmer": "I015661",
            "omschrijving": "BPTPNP-016X030-434-7552/1 PRINT&PROTECT 16X30MM"
        }
    ]
    
  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    What am I doing wrong?

    Its hard to say without knowing what happens.

    var data = table.row({ selected: true }).data();

    Seems like this should get the data for all the columns. Does it?

    var data = table.row({ selected: true }).data.Nummer;
    var data = table.row({ selected: true }).data()['Nummer'];

    These won't work because you don't have and object called 'Nummer. Try usingartikelnummmer` instead.

    Kevin

  • scotexscotex Posts: 3Questions: 1Answers: 0

    Hi,

    this worked

    var data = table.row({ selected: true }).data()['artikelnummmer'];
    

    Thanks for your help !

This discussion has been closed.