While all connector can filter data by url manipulation, only Grid and TreeGrid1) has native GUI for sorting, so below info mostly actual for those two components.
To enable server side filtering you can use one of the following in-header filter types while configuring dhtmlxGrid:
mygrid.setHeader("Column A, Column B"); mygrid.attachHeader("#connector_text_filter,#connector_select_filter")
When using text filter, no any additional configuration necessary. Grid will automatically send data about new entered text and filter server side using %mask% pattern. If you need change filtering pattern or implement more advanced logic - BeforeSelect server side event can be used.
Select rules can be modified directly by using Request.Rules collection that can be accessed by connector.
Define based on field filter
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.Rules.Add( new FieldRule("CreatedDate", Operator.GreaterOrEqual, "2009-01-01") ); }
Code above will filter items that were created this year.
Define expression filter
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.Rules.Add(new ExpressionRule("datepart(dw, CreatedDate) in (6,7)")); }
This example will return items that were registered on weekend
Each dhtmlxDataItem object has Skip property, setting true value to which will prevent it from rendering. You can handle ItemPrerender event and test item if it should be visible or not. Example below shows how to prevent items that has “is_hidden” property from being rendered.
void connector_ItemPrerender(object sender, ItemPrerenderEventArgs<dhtmlxTreeDataItem> e) { if (e.DataItem.DataFields["is_hidden"] == "1") e.DataItem.Skip = true; }
If you are using select filter you may need to define list of options in select box, it can be defined in one of 3 ways
connector.ExplicitOptions.Add(connector.Request.RequestedFields[0], "Alpha", "Beta", "Gamma");
or
connector.ExplicitOptions.Add((TableField)"FieldName", "Alpha", "Beta", "Gamma");
Example above will add 3 options (“Alpha”, “Beta”, “Gamma”) to the filter associated with the first column.
dhtmlxOptionsConnector filterConnector = new dhtmlxOptionsConnector("Country", "ISO", connector.Request.Adapter); //attach filter connector to first column of grid connector gridConnector.OptionsConnectors.Add(connector.Request.RequestedFields[0], filterConnector);
At first we create dhtmlxOptionsConnector that will fetch items, specify table and field name to take options title from, and then provide database adapter (Request.Adapter) already created for gridConnector. Finally, we add options connector to the first field of gridConnector.