Postback AFTER client side filter has been applied

4 posts, 1 answers
  1. Joaquín
    Joaquín avatar
    27 posts
    Member since:
    Jan 2012

    Posted 08 Feb 2013 Link to this post

    Hi guys,

    I have a grid which allows filtering by columns. I need the filter to perform a postback after a filter has been applied. Is there any way to do it?

    I have tried using AutoPostBackOnFilter="true", but it performs the postback before the filter has been applied in the client. The reason for which I need this is to enable or disable some radbuttons depending on the results of the filter; for example, if there are no rows once the filter has been applied, I want to disable the 'Edit' radbutton.

    I have tried to do it client side, using the onGridCreated event:

    var usuarioEsSupervisor;
            function afterGridCreation() {
    // Called from onGridCreated
                    // Mostrar el número de registros que hay en el grid

                    var grid = $find("<%= gridIncidencias.ClientID %>");
                    var MasterTable = grid.get_masterTableView();
                    var Rows = MasterTable.get_dataItems();
                    var filas = Rows.length;

                    var etiqueta = $get("<%=lblNumberOfIssues.ClientID %>");
                    etiqueta.innerHTML = filas;


                    // Desactivar los botones de eliminar y editar si el grid no contiene registros
                    var botonDelete = $find("<%=btnDeleteIssue.ClientID %>");
                    var botonDetails = $find("<%=btnEditIssue.ClientID %>");

                    if (filas > 0) {

                        if (usuarioEsSupervisor) {
                            botonDelete.set_enabled(true);
                        }
                        botonDetails.set_enabled(true);
                    }
            }

     However, for some reason that I dont know, the vars botonDelete and botonDetails get null value and, therefore, I cannot reach the buttons.

    Any idea please? Thank you.
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 13 Feb 2013 Link to this post

    Hi Joaquín,

    Thank you for contacting us.

    Please try the following approach:
    protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
    {
        if (e.EventInfo is GridInitializePagerItem)
        {
            int totalRowCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
            Button1.Enabled = (totalRowCount != 0);
        }
    }

    That should do the trick. Please give it a try and let me know about the result.

    All the best,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joaquín
    Joaquín avatar
    27 posts
    Member since:
    Jan 2012

    Posted 04 Mar 2013 Link to this post

    Hi Eyup,

    Thank you for your reply. I have not been able to implement the solution that you have suggested. However, finally I got the desired behaviour using:

    Protected Sub gridIncidencias_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles gridIncidencias.ItemCommand
     
            Select Case e.CommandName
     
                Case "Filter"
                    gridIncidencias.Rebind()
     
            End Select

    and then, in
    Protected Sub gridIncidencias_DataBound(sender As Object, e As System.EventArgs) Handles gridIncidencias.DataBound

    I perform the adjusts I need.

    Joaquín
  5. Answer
    Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 07 Mar 2013 Link to this post

    Hello Joaquín,

    Please do not forget to cancel the original Filter command using e.Canceled=true to avoid double rebinding the grid.

    Greetings,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top