Titamik
Titamik

Reputation: 39

Updating partial JS Api OcoberCMS

I'm trying to sort table using AJAX

ScheduleC.php

        public function onSort() {

            $groupId = (int)post('groupid');
            $professorId = (int)post('professorid');

            $schedules = Schedule::orderBy('date', 'desc')->get();

            if (($groupId) && ($groupId!='-1')) {
                $this->sortByGroup($groupId, $schedules);
            }

            if (($professorId) && ($professorId!='-1')) {
                $this->sortByProfessor($professorId, $schedules);
            }

            $this->schedule = $this->page['schedule'] = $schedules;
            
            return  $this->page['schedule'];
        }

default.php

<div id="schedule-table-container">
    {% partial '@schedule-table' %}
</div>

schedule.js

$(document).ready(function() {
    $('#sortschedule').submit(function(event) {
        event.preventDefault();
        $(this).request('onSort', {         
        update: {'schedulec::schedule-table': '#schedule-table-container'},
        success: function(data) {
            console.log(data);
            this.success(data);
        }
        });
    });
});

The function returns the correct data, but partial is not updated.

The most interesting is that the similar code is working at my another project. Please, help.

Upvotes: 0

Views: 40

Answers (2)

Pettis Brandon
Pettis Brandon

Reputation: 865

The true issue here is because you have the success option being called. Read more here. So your solution by not returning anything from the server doesn't execute the success() option stopping the ajaxUpdate.

"Success() | a callback function to execute in case of a successful request. If this option is supplied it overrides the default framework's functionality: the elements are not updated, the beforeUpdate event is not triggered, the ajaxUpdate and ajaxUpdateComplete events are not triggered. The event handler gets 3 arguments: the data object received from the server, the text status string and the jqXHR object. However, you can still call the default framework functionality calling this.success(...) inside your function."

Upvotes: 2

Titamik
Titamik

Reputation: 39

I solved the problem by removing return in the handler

Upvotes: 0

Related Questions