I added a button. There was a 'raw' problem here.

I added a button. There was a 'raw' problem here.

skitter9300skitter9300 Posts: 3Questions: 1Answers: 0
edited January 2021 in Free community support

hi guys!
I added a button. There was a 'raw' problem here!
This is my code
1. ajax for datatables

$.ajax({
                url : "url",
                type : "Post",
                data : param,
                dataType : 'text',
                success : function(data) {                      
                        var grid = JSON.parse(data);    
                        
                        table = $('#example').DataTable( {
                                "data" :grid,
                                "columns" : [                                                   
                                                { "data" : "BR_CD" },
                                                { "data" : "DEVC_UNO" },
                                                { "data" : "REG_YN" },
                                                { "data" : "OCRN_DATE" },
                                            { "data" : "OB_TYPE" },
                                            { "data" : "AC_DTS" },
                                            { "data" : "REQRE_TM" },
                                            { "data" : null, defaultContent: "<button>detail</button>"}                                             
                                            ],
                                "destroy": true,
                                "order": [[0, 'asc']],
                                "ordering": true
                            } );            
                    },
                error : function(request, status, error) {
                    console.log(error);
                    }
            });
  1. button function (added in 1.)
 $(document).on("click","button", "#example tbody ",function() {
        
            data = table.row($(this).parents('tr')).data();
            $("#modal_br").val(data.BR_CD);
            $("#modal_devc").val(data.DEVC_UNO);
            $("#modal_obty").val(data.OB_TYPE);
            $("#modal_mfbizNm").val(data.BR_CD);
            $("#modal_mfbizTel").val(data.BR_CD);

            $("#modal_btn").modal('show');
                       
    }); 

I was able to get the result I wanted, but 'raw' problems occur.
like
Uncaught TypeError: Cannot read property 'row' of undefined

What are the reasons and solutions?

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • skitter9300skitter9300 Posts: 3Questions: 1Answers: 0

    i solved "raw" problem lol but when modal close "Uncaught TypeError: Cannot read property 'BR_CD' of undefined" error in $("#modal_br").val(data.BR_CD);

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

    Try replacing table on line three with $('#example').DataTable(). - I suspect the problem is that your table variable is out of scope (it was defined in the ajax function).

    Colin

  • skitter9300skitter9300 Posts: 3Questions: 1Answers: 0
    edited January 2021

    thx colin! i can solved 'raw' problem using your answer.
    and i also solved "Uncaught TypeError: Cannot read property 'BR_CD'."
    just change this '$(document).on("click","button", "#example tbody ",function()' =>
    '$(document).on("click", "#example tbody > tr > td > button", function()'
    like this! thx colin!

This discussion has been closed.