Cannot set property 'id' of null in Datatable

Cannot set property 'id' of null in Datatable

ANDREANQLANDREANQL Posts: 1Questions: 1Answers: 0
edited July 2021 in DataTables 1.9

0

hello iam using datatable i get data from ajax and foreach data then add row to my datatable, but i always got error like this create:805 Uncaught TypeError: Cannot set property 'id' of null in line code "] ).node().id = obj.id;"

for my code

    $.ajax({
                        url : "<?php echo url('prod_bill_of_material/get-itemfg') ?>",
                        method : "GET",
                        success : function(data){
                            console.log(data);
                            // var trHTML = '';
                            var no = 1 ;
                            table_modal_itemfg.clear().draw();
                            var field="itemfg";
                            $.each(data, function( index , obj){

                                    table_modal_itemfg.row.add( [
 '<input type="hidden" readonly id="item_code_'+obj.id+'" value="'+obj.item_code+'"  class="form-control input-sm" data-toggle="tooltip" data-placement="top" title="'+obj.item_code+'">'+obj.item_code,
                                '<input type="hidden" readonly id="item_name_'+obj.id+'" value="'+obj.item_name+'"  class="form-control input-sm" data-toggle="tooltip" data-placement="top" title="'+obj.item_name+'">'+obj.item_name,                            
                                '<input type="hidden" readonly id="item_measur_'+obj.id+'" value="'+obj.item_measur+'"  class="form-control input-sm" data-toggle="tooltip" data-placement="top" title="'+obj.item_measur+'">'+obj.item_measur,                            
                                '<input type="hidden" readonly id="item_weight_'+obj.id+'" value="'+obj.item_weight+'"  class="form-control input-sm" data-toggle="tooltip" data-placement="top" title="'+obj.item_weight+'">'+obj.item_weight,                            
                                '<input type="hidden" readonly id="item_status_'+obj.id+'" value="'+obj.item_status+'"  class="form-control input-sm" data-toggle="tooltip" data-placement="top" title="'+obj.item_status+'">'+obj.item_status,      ~~~~
                                    ] ).node().id = obj.id;
                                table_modal_itemfg.draw(false);
                                no++;
                            });
                        }
                    });

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    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

Sign In or Register to comment.