META-INF.resources.primefaces.datagrid.datagrid.js Maven / Gradle / Ivy
/**
* PrimeFaces DataGrid Widget
*/
PrimeFaces.widget.DataGrid = PrimeFaces.widget.BaseWidget.extend({
init: function(cfg) {
this._super(cfg);
this.cfg.formId = $(this.jqId).closest('form').attr('id');
this.content = $(this.jqId + '_content');
if(this.cfg.paginator) {
this.setupPaginator();
}
},
setupPaginator: function() {
var $this = this;
this.cfg.paginator.paginate = function(newState) {
$this.handlePagination(newState);
};
this.paginator = new PrimeFaces.widget.Paginator(this.cfg.paginator);
},
hasBehavior: function(event) {
if(this.cfg.behaviors) {
return this.cfg.behaviors[event] !== undefined;
}
return false;
},
handlePagination: function(newState) {
var $this = this,
options = {
source: this.id,
update: this.id,
process: this.id,
formId: this.cfg.formId,
params: [
{name: this.id + '_pagination', value: true},
{name: this.id + '_first', value: newState.first},
{name: this.id + '_rows', value: newState.rows}
],
onsuccess: function(responseXML, status, xhr) {
PrimeFaces.ajax.Response.handle(responseXML, status, xhr, {
widget: $this,
handle: function(content) {
this.content.html(content);
}
});
return true;
},
oncomplete: function() {
$this.paginator.cfg.page = newState.page;
$this.paginator.updateUI();
}
};
if(this.hasBehavior('page')) {
var pageBehavior = this.cfg.behaviors['page'];
pageBehavior.call(this, options);
}
else {
PrimeFaces.ajax.Request.handle(options);
}
},
getPaginator: function() {
return this.paginator;
}
});