[ 4 posts ]

Scott

  • Username: scottskayak
  • Joined: Tue Aug 23, 2011 1:30 pm
  • Posts: 8
  • Offline
  • Profile

DataTables with Model and Model List

Post Posted: Tue Oct 18, 2011 6:41 am
+0-
Looking to see if anyone has built a DataTable DataSource for a ModelList?

I have a populated ModelList that I would like to display in a dataTable, looking around I do not see a direct implementation that would support this.

I don't have a lot of time to create a new plugin for the dataTable, so I may simply build a tabular View module for the moment, but if a solution exists I would like to take advantage of it.

Thanks
-Scott

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 514
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: DataTables with Model and Model List

Post Posted: Tue Oct 18, 2011 8:30 am
+0-
There's nothing out of the box that I know of today, but the plan for DataTable in 3.5.0 is to be based on a model/modellist core with widget view(s).

Scott

  • Username: scottskayak
  • Joined: Tue Aug 23, 2011 1:30 pm
  • Posts: 8
  • Offline
  • Profile

Re: DataTables with Model and Model List

Post Posted: Wed Oct 19, 2011 4:17 am
+0-
I wrote a short plugin to the dataTable that allows the datatable to read my data.

Code:
YUI.add("datatableModelPlugin", function(Y) {
   function DatatableModelPlugin(config){
      DatatableModelPlugin.superclass.constructor.apply(this,arguments);
   }
   DatatableModelPlugin.NAME='datatableModelPlugin';
   DatatableModelPlugin.NS='datatableModelPlugin';
   Y.extend(DatatableModelPlugin,Y.Plugin.Base,{
      initializer: function() {
         this.beforeHostMethod('formatDataCell',this.formatDataCell);
      },
      formatDataCell: function (o) {
           o.value = o.record.get(o.field);
           return new Y.Do.Halt("",o.formatter.call(this, o));
       }
   });
   Y.namespace("MyProject").DatatableModelPlugin = DatatableModelPlugin;
});


I am taking advantage of a model list being an ArrayList then simply exchanging the default behavior of the datatable that uses o.value = o.record[o.field] with a .get() call.

I have only gone through some basic testing on this but it appears to do the trick.

This is probably more generic than just reading a model, I would think it could read any array of Attribute based entities.

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 514
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: DataTables with Model and Model List

Post Posted: Wed Oct 19, 2011 10:15 am
+0-
Nice. That can be a reference implementation for folks until the DT plumbing is updated. It should be noted that calling get() for each cell will impact performance, but the difference from the current performance might not be noticeable unless the data sets are larger.

Performance is also in the plan for DT 3.5.0.
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum