call a function on mrender

call a function on mrender

carl03spinosacarl03spinosa Posts: 3Questions: 1Answers: 0

I got this datatable:

    var table1 = $('#epub_table').dataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            "type": "POST",
            "url": "<?php echo base_url('school_admin/epub_json'); ?>"
        },
        "columns": [
            {"data": "title"},
            {"data": "edition"},
            {"data": "grade_level"},
            {"data": "epub_id",
                "mRender": function (data, type, row) {
                    //var temp1 = row.epub_id;
                    //var temp2 = row.school_id;

                    return function testme();



                    }
            },
        ],
        "lengthMenu": [[10, 25, 50, 75, 100, -1], [10, 25, 50, 75, 100, "All"]],
        "order": [[0, "desc"]],

    });

and I want to call the function:

    function testme(){
        var temp1 = 16;
        var temp2 = 668;

        $.ajax(
           { url: location.origin + "/portal/school_admin/get_book_dlcount/" + temp1 + "/" + temp2,
              success: function(result){
                return result; 
              }
           }
        );
    }

inside the mrender of the datatable. How do I do this? or is there a better way for me to get data from a controller in codeigniter? thanks

Answers

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929

    Its not recommended to use ajax calls with columns.render as this could slow down the table display. Is it possible to get the information needed in the main ajax request as part of each row?

    Kevin

  • carl03spinosacarl03spinosa Posts: 3Questions: 1Answers: 0

    well as you could see im calling a function from my controller (url: location.origin + "/portal/school_admin/get_book_dlcount/" + temp1 + "/" + temp2) and i need the data that it returns on the last column of the table. to be exact i need the count of arrays that it will return from the controller.

    Inside the controller:

    public function get_book_dlcount() {
    $dlcount = $this->Admin_model->_ebooks_withaccess($this->uri->segment(3), $this->uri->segment(4));
    return $dlcount;
    }

    And inside the model:

    public function _ebooks_withaccess( $book_id, $sc_id ) {
        $this->db->select('tbl_users.id AS user_id, tbl_users_data.fname AS first_name, tbl_users_data.lname AS last_name,
                 tbl_users.grade_level as grade_level, tbl_book_access.status as status');
        $this->db->from('tbl_book_access');
        $this->db->join('tbl_users_data', 'tbl_users_data.user_id = tbl_book_access.user_id');
        $this->db->join('tbl_users', 'tbl_users.id = tbl_book_access.user_id');
        $this->db->where('tbl_book_access.book_id', $book_id);
        $this->db->where('tbl_users.sc_id', $sc_id);
    
        $query = $this-> db -> get();
        return ($query -> num_rows() > 0) ? $query -> result() : false;
    }
    

    }

  • carl03spinosacarl03spinosa Posts: 3Questions: 1Answers: 0

    or better if there's a way for me in the column.render which I can call a controller directly and have it return its data as the column.render value. This is for CODEIGNITER.

This discussion has been closed.