How to occupy gridView with AJAX on Yii2?

This is my first time using the Yii2 Framework, so I don’t have much knowledge of the features or what it offers.

Currently I integrate Ajax as I do with all projects with script and a table that updates the data according to the option you select.

The issue is that the project occupies GridView for the tables and I was asked that all the tables were the same, ie, that the table I did now is with GridView and do not know how to implement Ajax with the Gridview.

I leave you my HTML work:


<div class="course-index container">
    <div class="row">
        <div class="col-sm-4">
            <div class="panel">
                <div class="panel-heading">
                <div class="panel-body">
                    <div class="refresh-course">
                        <table class="table">
                            <tbody id="course-item">
                                <?php foreach ($courses as $key): ?>
                                <tr class="course-<?= $key['id'] ?> course-tr" id="<?= $key['id'] ?>">
                                <td class="name"><?= $key['name'] ?></td>
                                <td><span class="badge badge-info"><?= $key['amount'] ?></span></td>
                                <td><a title="Listar estudiantes" class="list-course" data-id="<?= $key['id'] ?>"><i class="fa fa-chevron-right"></i></a></td>
                                <?php endforeach; ?>
        <div class="col-sm-8">
            <div class="panel">
                <div class="panel-heading">
                    Estudiantes inscritos
                <div class="panel-body">
                    <div class="refresh-students">
                        <table class="table table-striped table-bordered tablesorter" id="report-table">
                                <th>Fecha inicio</th>
                                <th>% Completados</th>
                                <th>Tiempo realizado</th>
                            <tbody id="resultData">


<script type="text/javascript">
function initializate(){
    $('#report-table > tbody').empty();
    $("#course-item tr[id]").click(function(){
        var order = $(this).attr('id');
            url: '<?= Url::to(['default/load/']); ?>',
            type: 'POST',
            data : {id: order},
                $('#report-table > tbody').empty();
                var html = '';
       => {
                    html += '<tr>' +
                    '<td>' + + '</td>' +
                    '<td style="text-align: center;">' + (element.start_date == null ? '-' : new Date(element.start_date).toLocaleDateString("en-US") ) + '</td>' +
                    '<td style="text-align: center;">' + element.percent + '</td>' +
                    '<td>' + element.time + '</td>' +

There are extensions that exist, such as:

Or you may simply prefer to upgrade to using which include numerous extra features that you may appreciate.

Or am I misunderstanding the request and you are looking to add a checkbox for each row to be to apply an action against multiple rows.

Mostly fill the gridview with AJAX as it appears in the script code

I’m afraid I’m still not clear on what you are after exactly. “as it appears in the script code”? Can you give a concrete example? Do you mean attach events to the grid table row, cell, …?

Perhaps someone else will be able to help.

I want to fill a table through ajax occupying the Gridview

I’m not sure what you mean by “occupy” …

Anyway, I’d like to recommend that you take your time to play with the Gii’s CRUD generator before you resume your work.
GridView works quite nicely with PJAX out of the box. You usually don’t have to write a single line of javascript code to implement what you want.