Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Datatable adding a new row with row.add.draw() but with different content then the other rows

I am trying to add a new row to the datatable loaded by ajax, but need the content of the new row to be different then the previous rows. I am using row.add.draw() and a new row is added to the table but with the same fields as the other rows. I need the new row to have a "ADD" button instead of "EDIT" and "DEL".

Here is the columns of the table in general:

columns: [
            { data: 'mls' },
            { data: 'steet' },        
            { data: 'city' },
            { data: 'zip' },
            { data: 'country' },             
            {'data': null, 'render': function (data, type, row, meta) {
                    return '<button id="del-'+row.mls+'" class="btn btn-danger btn-xs edit_active" data-title="Delete" data-toggle="modal" data-target="#del" >Delete</button>';
                 }

            },

this is the function of row.add.draw() :

$("#cur_act_tbl").DataTable().row.add({"mls": '',"street": '',"city": '',"zip": '',"country": ''}).draw();

new row with different button

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In your data add a type property that will tell DataTables if this is a new row or an existing one. You will need to modify your Ajax return to include this property also (but with the value "existing")

{"mls": '',"street": '',"city": '',"zip": '',"country": '', "type": "new"}

Then in DataTables you just need to check for this property and return the corresponding button.

columns: [
    { data: 'mls' },
    { data: 'steet' },        
    { data: 'city' },
    { data: 'zip' },
    { data: 'country' },             
    { render: (data, type, row, meta) =>  {
        let btn = '';
        if(row.type == 'new') {
            btn = '<button id="add-'+row.mls+'" class="btn btn-primary btn-xs edit_active" data-title="Add" data-toggle="modal" data-target="#add">Add</button>';
        } else {
            btn = '<button id="edit-'+row.mls+'" class="btn btn-info btn-xs edit_active" data-title="Edit" data-toggle="modal" data-target="#edit">Edit</button>';
        }
        return btn;
    }

],
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!