0

I have added some new filters to the datalists in Alfresco Share. Now I want one of my new filters to be selected by default (instead of the "All" default filter) when entering my datalist.

I have found out that the default filter is set in the constructor of the YUI2-component responsible for rendering the data-list:

/**
* DataGrid constructor.
* 
* @param htmlId {String} The HTML id of the parent element
* @return {Alfresco.component.DataGrid} The new DataGrid instance
* @constructor
*/


Alfresco.component.DataGrid = function(htmlId)
   {
      Alfresco.component.DataGrid.superclass.constructor.call(this, "Alfresco.component.DataGrid", htmlId, ["button", "container", "datasource", "datatable", "paginator", "animation", "history"]);
  // Initialise prototype properties
  this.datalistMeta = {};
  this.datalistColumns = {};
  this.dataRequestFields = [];
  this.dataResponseFields = [];
  this.currentPage = 1;
  this.totalRecords = 0;
  this.showingMoreActions = false;
  this.hideMoreActionsFn = null;
  this.currentFilter =
  {
     filterId: "all",
     filterData: ""
  };
  this.selectedItems = {};
  this.afterDataGridUpdate = [];

I have already extended this component for other purposes (rendering columns in a special way etc) and now I want to change the this.currentFilter.filterId to "active" (which is my new filter).

This is how you extend the class and overrides a method:

 // Extend default DataList...
  YAHOO.extend(Datalist.custom.DataGrid, Alfresco.component.DataGrid,
  {
    onFilterChanged: function CustomDL_onFilterChanged(layer, args)
    {
      // Call super class method...
      Datalist.custom.DataGrid.superclass.onFilterChanged.call(this, layer,args);
  // Pop-up a message...
  Alfresco.util.PopupManager.displayMessage({
    text: "Filter Changed!"
  });
}

}); })();

However, I have not found out a way to override a class property, for example "this.currentFilter", I only succeed in overriding methods.

I have looked in to the YUI.lang.augmentProto and YUI.lang.augmentObject without really understanding how to do it.

billerby
  • 1,977
  • 12
  • 22

1 Answers1

1

You could override the initial value of the property but it wouldn't make much of a difference since it gets initialized in the constructor anyway so whatever the initial value might have been, it would be lost.

You should override the constructor, in the same way as DataGrid overrides the constructor of its base class. Call the original constructor and then set a new value to the property.

user32225
  • 854
  • 7
  • 7