How this should be done?

How this should be done?

kunjkunj Posts: 2Questions: 1Answers: 0
edited December 2018 in Free community support

I am getting my data from database. The issue is I want to apply click function to button which is created by render in angular 6.

 private SabhaList2() {
    $(".content-wrapper").addClass("pt-0");
    let exampleId2: any = $('#sabhaList');
    this.tableWidget2 = exampleId2.DataTable({
      select: false,
      orderCellsTop: true,
      dom: 'Bfrtip',
      destroy: true,
      colReorder: true,
      fixedHeader: {
        header: true,
      },
      scrollY: '90vh',
      scrollX: '100wv',
      bInfo: false,
      bFilter: false,
      paging: false,
      buttons: [
      ],
      data: this.tableData,
      "columns": [
        { title: this.keys[0],data: this.keys[0] },
        { title: this.keys[1],data: this.keys[1] },
        { title: this.keys[2],data: this.keys[2] },
        { title: this.keys[3],data: this.keys[3] },
        { title: this.keys[4],data: this.keys[4] },
        { title: this.keys[5],data: this.keys[5] },
        { title: this.keys[6],data: this.keys[6] },
        { title: this.keys[7],data: this.keys[7] },
        { title: this.keys[8],data: this.keys[8] },
        { title: this.keys[9],data: this.keys[9] },
        { title: this.keys[10],data: this.keys[10] },
        { title: this.keys[11],data: this.keys[11] },
        { title: this.keys[12],data: this.keys[12] },
      ],
      columnDefs: [{
        'targets': 0,
        'searchable': false,
        'orderable': false,
        'className': 'custom-checkbox',
        'render': function (data, type, full, meta) {
          return '<input type="checkbox" onchange ="inlineidgroup(' + data + ')" id="' + data + '" name="' + data + '" class="select-checkbox" value="' + $('<div/>').text(data).html() + '"> <button type="button" onclick="inlineidgroup('+data+')">Show Id</button>';
        }
      }],
    });
  }

I am storing my data and its keys in 2 different arrays named "tableData" and "keys" respectively. The Change and Click function is not working.

I receive an error saying:
Uncaught ReferenceError: inlineidgroup is not defined
at HTMLButtonElement.onclick (Attendance:1)

they are not able to find the below function:

  inlineidgroup(data) {
    console.log(data);
  }

Answers

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

    Hi @kunj ,

    It would depend on the scope of where that function is defined. Is it in the same file? 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

  • kunjkunj Posts: 2Questions: 1Answers: 0
    edited December 2018

    Hii Colin,
    Thanks for your precious time.
    Surely will upload test case in some time.

This discussion has been closed.