The grid widget is a feature rich tool that allows to do data analysis. The data from the back end can be fetched and displayed in the grid widget.
Following features are available in this version:
Removal of rows.
Hiding and displaying of columns.
Reordering the columns.
Sorting of data.
Filtering of data with a single value.
Exporting data to excel.
Print preview.
Statistical analysis (frequency distribution and the mean, median, mode calculations).
Attributes of Grid widget:
id : The unique name of the widget.(Required)
total: The length of the data that is passed.(Required)
required : A flag (true/false) which denotes whether a value is required.
value : A default value.(Optional)
selectable: A flag (true/false) which will determine whether the rows in the grid will be selectable or not. (Optional)
stripe: A flag (true/false) which will determine whether the rows in the grid will be striped alternately.
stats: A flag (true/false) which will determine whether the statistics feature will be available or not.
excel: A flag (true/false) which will determine whether the exporting the data to excel feature will be available or not.
width : The width of the entire grid. (Optional)
height : The height of the entire grid. (Optional)
statusbar: A flag (true/false) which will determine whether the status bar will be shown or not.
draggable : A flag (true/false) which will determine whether the contents can be dragged with mouse.
droppable : A flag (true/false) which will determine whether the contents can be dragged and dropped with mouse.(Optional)
droppableoptions : A dictionary containing the droppable options. (Optional)
formula : A WidgiCalc formula.(Optional)
onclick : A custom event handler.(Optional)
onchange : A custom event handler.(Optional)
Sample Code:
<gridbox id='my_grid' total='10' />
Example:
import aphrodite, json
from plugins.CheetahPlugin.CheetahPlugin import CheetahRender
from idea import Idea
@iris.expose
def index(self):
dat = []
dat=[{'id':'a1','name':'krish','class':'XII','Sub':'Economics','Marks':'90'},{'id':'a2',
'name':'krish','class':'XII','Sub':'Maths','Marks':'80'},{'id':'a3','name':'krish',
'class':'XII','Sub':'English','Marks':'30'},{'id':'a4','name':'krish','class':'XII',
'Sub':'Bengali','Marks':'20'},{'id':'a5','name':"krish",'class':'XII','Sub':'Bengali',
'Marks':'60'}]
gid = iris.root.analytics.grid.createGrid(dat)
return CheetahRender(data={'grid_id':gid,'grid_length':len(dat)},template="index")
Analytics Framework:
If you want to display data from the backend and do analysis on it, then the data needs to be passed to the analytics framework. This framework then processes the data and creates a format which can be passed to the grid widget (which is also a part of the framework) for displaying that data in the browser. The analytics framework is there in the apps folder inside the brainwave folder.
gid = iris.root.analytics.grid.createGrid(dat)
This line of code will send the data to the analytics framework, which will process and format the data and return an id of the grid. The id is then passed to the cheetah template file (see the template code below) along with the length of the data (which is a list of dictionary in this case) to the grid template which will take this data and render it for displaying.
Note: To know more about python you need to consult the tutorials available online at http://docs.python.org/tut/ and to know more about coding in brainwave consult the tutorials at http://www.brainwavelive.com/developers/
The template file code for the above example will be the following:
The above code contains the template for the grid widget, which will display the grid. The template will accept the id and the length of the data passed from the python code and then displays the data in the browser.
The analytics framework also supports the use of "Idea" (to know more about it refer the Idea database framework at http://www.brainwavelive.com/developers/ideaframework.html ) which contains several APIs for putting and fetching data to and from the database. Thus, the Idea object can be directly passed to the grid to display data from the backend database.