Filtering through

4 posts, 0 answers
  1. Ricardo
    Ricardo avatar
    10 posts
    Member since:
    Apr 2014

    Posted 28 Nov 2014 Link to this post

    Hi, I need to filter the Grid through a Client DataSource in client side.
    I can filter the grid applying the filter to the grid directly, however it is not possible filter using non visible columns, so I tried to apply a filter the grid adding filter expressions in the ClientDataSource but nothing happens.
    For example
        var datasource = $find('MyClientDataSource');
        datasource.get_filterExpressions().add({ fieldName: "MyField", value: "MyValue", operator:Telerik.Web.UI.ClientDataSource.FilterOperator.EqualTo });
        tableView.rebind();

    This code doesnt work. It is possible do this kind of filtering?
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 02 Dec 2014 Link to this post

    Hi Ricardo,

    Filtering by data field that is not included in the RadGrid structure is not supported scenario and the only possible way for using the masterTableView filter() method would be to have a column with that data field with Display property set to false. In this way you will be able to filter by that data field and still avoid displaying the column.

    Another approach would be to pass custom parameter to the service and apply the filtering manually. You can take a look at the following demo, demonstrating how to use OnCustomParameter event:


    Regards,
    Konstantin Dikov
    Telerik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricardo
    Ricardo avatar
    10 posts
    Member since:
    Apr 2014

    Posted 02 Dec 2014 in reply to Konstantin Dikov Link to this post

    Ok, yes. I've already implemented the filtering in that way, but would be great to have that functionality implemented in ClientDataSource.

    Another question, I have declared in the same grid (always connected to a ClientDataSource) many fields with aggregates in the following way:

                        <telerik:GridNumericColumn 
                            DataField="Value" 
                            DataFormatString="{0:C0}"
                            DataType="System.Decimal"
                            NumericType="Currency"
                            Aggregate="Sum"
                            FooterAggregateFormatString="{0:C0}">
                        </telerik:GridNumericColumn>

    The footer format string does not work. Am I doing something wrong?

    I've seen that if I add agregates to the ClientDataSource and apply a filter to the grid using the tableview object, the associated ClientDataSource object reflect the filtering and recalculates accordingly the aggregates. So I tried to update some external controls with the resulting aggregated values but I would like to format the resulting values in client side.
    Could you give me some advice to achieve that behavior?

    Thanks for your support.





  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 05 Dec 2014 Link to this post

    Hi Ricardo,

    Thank you for getting back to us.

    It seems that there is a bug for some format strings set to the FooterAggregateFormatString when client-side binding is used.

    There is also an issue with the current format that you are using {0:C0}. I could suggest the following temporary workaround that will use the DataFormatString and will apply it to the Footer:
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                Telerik.Web.UI.GridTableView.prototype._updateAggregates = function (row, computedAggregates) {
                    var AggregateMap = ["", "sum", "min", "max", "last", "first", "count", "average", "countDistinct", "custom"];
                    var columns = this.get_columns();
                    for (var c = 0 ; c < columns.length ; c++) {
                        var column = columns[c];
                        if (column._data.Aggregate && column._data.DataField) {
                            var cell = this._getCellByColumnUniqueNameFromTableRowElement(row, column._data.UniqueName);
                            if (computedAggregates[column._data.DataField]) {
                                var aggregateFormat = column._data.AggregateClientFormatString;
                                if (aggregateFormat == "{0}") {
                                    aggregateFormat = column._data.DataFormatString;
                                }
     
                                if (aggregateFormat.indexOf("{0}") >= 0) {
                                    cell.innerHTML = column._data.AggregateClientFormatString.replace("{0}", computedAggregates[column._data.DataField][AggregateMap[column._data.Aggregate]]);
                                }
                                else if (aggregateFormat != "") {
                                    var computedAggregates = computedAggregates[column._data.DataField][AggregateMap[column._data.Aggregate]];
                                    cell.innerHTML = String.localeFormat((aggregateFormat == "") ? "{0}" : aggregateFormat, computedAggregates);
                                }
                                else {
                                    cell.innerHTML = computedAggregates[column._data.DataField][AggregateMap[column._data.Aggregate]];
                                }
                            }
                            else {
                                cell.innerHTML = "";
                            }
                        }
                    }
                }
     
                Telerik.Web.UI.GridTableView.prototype.updateAggregates = function (computedAggregates) {
                    var footerRow = null;
                    if (this.get_element().tFoot) {
                        footerRow = this.get_element().tFoot.rows[0];
                    }
                    if (!footerRow && this._owner.GridFooterDiv && this._owner.GridFooterDiv.children[0]) {
                        footerRow = this._owner.GridFooterDiv.children[0].rows[1];
                    }
                    if (footerRow && footerRow.className == "rgFooter") {
                        this._updateAggregates(footerRow, computedAggregates);
                    }
                }
            </script>
        </telerik:RadCodeBlock>
    </form>

    Please add the above just before your form's closing tag.


    Best Regards,
    Konstantin Dikov
    Telerik
Back to Top