This is a migrated thread and some comments may be shown as answers.

Postback AFTER client side filter has been applied

3 Answers 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joaquín
Top achievements
Rank 2
Joaquín asked on 08 Feb 2013, 12:33 PM
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.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 13 Feb 2013, 03:05 PM
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.
0
Joaquín
Top achievements
Rank 2
answered on 04 Mar 2013, 05:20 PM
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
0
Accepted
Eyup
Telerik team
answered on 07 Mar 2013, 09:04 AM
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.
Tags
Grid
Asked by
Joaquín
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Joaquín
Top achievements
Rank 2
Share this question
or