Sorry guys, I have a problem. how to get an id value from a column so i can use in url

Sorry guys, I have a problem. how to get an id value from a column so i can use in url

merchantguildmerchantguild Posts: 5Questions: 2Answers: 0
    var table = $('#relasiKeluarga').DataTable({
        "ajax": "http://pintas_simulasi_3.test/api/relasi_keluargas",
        "columns": [{
                //defaultContent: '<input type="button" class="name" value="Name"/><input type="button" class="position" value="Position"/>'

            },
            {
                "data": "id"
            },
            {
                "data": "relasi_keluarga"
            },
            {
                "data": "is_active"
            }
        ],
        "columnDefs": [{
                "targets": [1],
                "visible": false
            },
            {
                "className": "dt-body-center",
                "targets": [0],
                "render": function(data, type, row, meta) {
                    return '<a class="btn btn-default btn-sm mx-2" href="http://url/{{ id }}"><i class="far fa-eye"></i></a>' +
                        '<a class="btn btn-default btn-sm" href="http://url/{{ id }}"><i class="far fa-edit"></i></a>';
                },
            }
        ],

    });

    $('#relasiKeluarga tbody').on('click', '.relasi_keluarga', function() {
        var row = $(this).closest('tr');

        var data = table.row(row).data().relasi_keluarga;
        console.log(data);
    });


    $('#relasiKeluarga tbody').on('click', '.is_active', function() {
        var row = $(this).closest('tr');

        var data = table.row(row).data().is_active;
        console.log(data);
    });

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You can use cell().node() to get the node, and then use jQuery's attr to get the ID from that node.

    Colin

  • merchantguildmerchantguild Posts: 5Questions: 2Answers: 0
    edited January 2022

    mr collin and how to get an id on unvisible column id, and than passit to return button {{ id }} ... sorry my collin I'm new in programming world

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961
    Answer ✓

    Read the columns.render docs. The row parameter has all the data for the row. Instead of "http://url/{{ id }}"> try "http://url/{{ row.id }}">. If you still need help then post a test case as Colin requested.

    Kevin

  • merchantguildmerchantguild Posts: 5Questions: 2Answers: 0

    @kthongren thanks for the answer sir, it really helped me...

  • merchantguildmerchantguild Posts: 5Questions: 2Answers: 0

    @colin thanks for the directions sir B) B)

Sign In or Register to comment.