Skip to content

Commit

Permalink
Improve internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Feb 16, 2024
1 parent 34a2a1e commit 8f9ed12
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
46 changes: 29 additions & 17 deletions dist/js/datatables-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ DatatableFilter = function () {
// update DT state
this._set_state(state);
// save DT state
return this._save();
return this._save_state();
}
}, {
key: "has_state_for",
Expand All @@ -567,12 +567,14 @@ DatatableFilter = function () {
}, {
key: "set_search_value",
value: function set_search_value(column_id, value) {
return this._get_instance().aoPreSearchCols[column_id].sSearch = value;
this.info("Set search value (".concat(column_id, ")"));
return this._set_search_value(column_id, value);
}
}, {
key: "run_filter",
value: function run_filter(column_id, value) {
return this.instance.fnFilter(value, column_id);
this.info("Run filter (".concat(column_id, ")"));
return this._run_filter(column_id, value);
}
}, {
key: "reset_filters",
Expand All @@ -583,12 +585,12 @@ DatatableFilter = function () {
filter = ref[_column_id];
filter.reset(event);
}
return this._draw();
return this._draw_instance();
}
}, {
key: "apply_default_filters",
value: function apply_default_filters(event) {
this.info('apply_default_filters');
this.info('Apply default filters');
return this._apply_filters(event);
}

Expand Down Expand Up @@ -648,7 +650,7 @@ DatatableFilter = function () {
};
$(this.datatable.dt_id).off('xhr.dt').on('xhr.dt', ondraw_callback);
// we need to make sure that the yadcf state will be saved after page reload
return this._save();
return this._save_state();
}
}, {
key: "_apply_filters",
Expand All @@ -670,7 +672,7 @@ DatatableFilter = function () {
}
// reload datatable
if (event.type === 'click') {
return this._draw();
return this._draw_instance();
}
}

Expand Down Expand Up @@ -706,16 +708,6 @@ DatatableFilter = function () {
}
return results;
}
}, {
key: "_save",
value: function _save() {
return this._get_instance().oApi._fnSaveState(this._get_instance());
}
}, {
key: "_draw",
value: function _draw() {
return this.instance.fnDraw(this._get_instance());
}
}, {
key: "_instance_present_for",
value: function _instance_present_for(method) {
Expand All @@ -731,6 +723,21 @@ DatatableFilter = function () {
value: function _get_instance() {
return this.instance.fnSettings();
}
}, {
key: "_draw_instance",
value: function _draw_instance() {
return this.instance.fnDraw(this._get_instance());
}
}, {
key: "_run_filter",
value: function _run_filter(column_id, value) {
return this.instance.fnFilter(value, column_id);
}
}, {
key: "_set_search_value",
value: function _set_search_value(column_id, value) {
return this._get_instance().aoPreSearchCols[column_id].sSearch = value;
}
}, {
key: "_get_state",
value: function _get_state() {
Expand All @@ -741,6 +748,11 @@ DatatableFilter = function () {
value: function _set_state(state) {
return this._get_instance().oLoadedState = state;
}
}, {
key: "_save_state",
value: function _save_state() {
return this._get_instance().oApi._fnSaveState(this._get_instance());
}
}]);
return DatatableFilter;
}(_extendable["default"]);
Expand Down
40 changes: 25 additions & 15 deletions src/model/datatable_filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DatatableFilter extends Extendable
@_set_state(state)

# save DT state
@_save()
@_save_state()


has_state_for: (column_id) ->
Expand All @@ -86,21 +86,23 @@ class DatatableFilter extends Extendable


set_search_value: (column_id, value) ->
@_get_instance().aoPreSearchCols[column_id].sSearch = value
@info "Set search value (#{column_id})"
@_set_search_value(column_id, value)


run_filter: (column_id, value) ->
@instance.fnFilter value, column_id
@info "Run filter (#{column_id})"
@_run_filter(column_id, value)


reset_filters: (event) ->
for _column_id, filter of @loaded_filters
filter.reset(event)
@_draw()
@_draw_instance()


apply_default_filters: (event) ->
@info 'apply_default_filters'
@info 'Apply default filters'
@_apply_filters(event)


Expand Down Expand Up @@ -153,7 +155,7 @@ class DatatableFilter extends Extendable
$(@datatable.dt_id).off('xhr.dt').on('xhr.dt', ondraw_callback)

# we need to make sure that the yadcf state will be saved after page reload
@_save()
@_save_state()


_apply_filters: (event) ->
Expand All @@ -170,7 +172,7 @@ class DatatableFilter extends Extendable

# reload datatable
if event.type == 'click'
@_draw()
@_draw_instance()


# (<jQuery event object>, <DataTables settings object>, <State information to be saved>)
Expand All @@ -194,14 +196,6 @@ class DatatableFilter extends Extendable
filter.reload(event)


_save: ->
@_get_instance().oApi._fnSaveState @_get_instance()


_draw: ->
@instance.fnDraw @_get_instance()


_instance_present_for: (method) ->
if !@instance? and !@_get_instance()?
@error "#{method}: Datatable instance is null"
Expand All @@ -214,6 +208,18 @@ class DatatableFilter extends Extendable
@instance.fnSettings()


_draw_instance: ->
@instance.fnDraw(@_get_instance())


_run_filter: (column_id, value) ->
@instance.fnFilter(value, column_id)


_set_search_value: (column_id, value) ->
@_get_instance().aoPreSearchCols[column_id].sSearch = value


_get_state: ->
@_get_instance().oLoadedState

Expand All @@ -222,4 +228,8 @@ class DatatableFilter extends Extendable
@_get_instance().oLoadedState = state


_save_state: ->
@_get_instance().oApi._fnSaveState(@_get_instance())


export default DatatableFilter

0 comments on commit 8f9ed12

Please sign in to comment.