0

I'm trying to add a button in a datatable row with the following code:

$("#tbllandinfo").DataTable({
            searching: false,
            ordering: false,
            paging: false,
            bInfo: false,   
            ajax: {
                url: '/land_and_crops/id/' + $("#eid").val(),
                dataSrc: '', 
            },
            columns: [
                { data: 'ldacres' },            
                { data: 'ldyields' },           
                { data: 'cname' },
            { 
                sortable:false,
                defaultContent:  "<button class='btn btn-danger btn-delete form-control pull-right' dbcolid='ldid' dbcolidval= dbtable='land_det'>X</button>",
            }
        ]
    });

The button displays but the problem I'm facing is that I need to put the value of ldid, that comes from ajax JSON into the dbcolidval attribute in the button.

Every row button will have its own value.

Sample data:

 {"ldid":4,"ldentity":7,"ldacres":"5.00","ldyields":2,"ldcrop":5,"cname":"RICE"},

 {"ldid":7,"ldentity":7,"ldacres":"10.00","ldyields":1,"ldcrop":6,"cname":"MAIZE",

 {"ldid":6,"ldentity":7,"ldacres":"4.00","ldyields":1,"ldcrop":3,"cname":"CORN"}

1 Answer 1

2

Use render instead of defaultContent. See discussed here: (https://datatables.net/forums/discussion/23649/how-do-i-access-columns-data-inside-of-defaultcontent)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.