jQWidgets Forums

jQuery UI Widgets Forums ASP .NET MVC Asp.net core 1.1.2 jqxgrid paging not firing

This topic contains 4 replies, has 2 voices, and was last updated by  rubenfernande3 8 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • rubenfernande3
    Participant

    Anyone has tested a grid with VIRTUAL MODE in asp.net core 1.1.2?. The first time i show the data it works. When i sort it works. But when i click the next page arrow or the previous page arrow the aplication doesn´t call again to my url action.


    Peter Stoev
    Keymaster

    Hi rubenfernande3,

    The ASP .NET MVC Tag Helper does not use virtual mode, it uses another approach called server processing. For reference, please refer to the Grid’s ASP .NET Tag helper demos on our web site. The server processing also requires implementation of the server side.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rubenfernande3
    Participant

    Peter i´m not using any Tag Helper. I use only JavaScript.

    Client side:

    var source =
                {
                    datatype: "json",
                    datafields:
                        [{ name: 'Codigo', type: 'int' },
                         { name: 'Descripcion', type: 'string' }
                        ],
                    url: '@Url.Action("GetPageData", "PrincipioActivo")',
                    // update the grid and send a request to the server.
                    filter: function () {
                        $("#jqxgrid").jqxGrid('updatebounddata', 'filter');
                    },
                    // update the grid and send a request to the server.
                    sort: function () {
                        $("#jqxgrid").jqxGrid('updatebounddata', 'sort');
                    },
                    root: 'Rows',
                    beforeprocessing: function (data) {
                        source.totalrecords = data.TotalRows;
                    },
                    addrow: function (rowid, rowdata, position, commit) {
                      
                        var x = callAjax(rowdata, 'PrincipioActivo', 'Add', 'POST');
                      
                        x.always(function (resultado) {
                            //always execute despite failure/success
                        
                            if (resultado.success === true)
                            {
                                alert("Principio activo insertado");
                                $('#jqxgrid').jqxGrid('updatebounddata');
                            }
                            else
                            {
                                alert("Ha ocurrido un error: " + resultado.message);
                                commit(false);
                            }
                        });
    
                    },
                    deleterow: function (rowid, commit) {
                        var row = $('#jqxgrid').jqxGrid('getrowdatabyid', rowid);
    
                    }
                    };
    
                var dataadapter = new $.jqx.dataAdapter(source,
                    {
                        loadError: function (xhr, status, error) {
                            alert(error);
                        }
                    });
    
                var theme = 'energyblue';
    
                // initialize jqxGrid
                $("#jqxgrid").jqxGrid({
                    source: dataadapter,
                    pageable: true,
                    virtualmode: true,
                    theme: theme,
                    localization: getLocalizationGrid(),
                    width: '95%',
                    rendergridrows: function (obj) {
                        return obj.data;
                    },
                    columns: [
                        { text: 'Codigo', datafield: 'Codigo' },
                        { text: 'Descripción', datafield: 'Descripcion' }
                    ]
                });

    Server side:

    [HttpGet, ActionName("GetPageData")]
            public string GetPageData(string sortdatafield, string sortorder, int pagesize, int pagenum)
            {
    
                var lista = _repositorio.GetPageDataSkip<PrincipioActivo>(pagesize, pagenum);
    
                
                var result = new { TotalRows = lista.Entities.Count, Rows = lista.Entities };
    
                
                var y = JsonConvert.SerializeObject(result);
                return y;
            }

    First time rendering the view the GetPageData is called. If i click over next page or previous page arrow it doesn´t work. It doesn´t fire the event. I´m debugging and there is no call to getpageDate when i try to go to another page.


    Peter Stoev
    Keymaster

    You should check whether you can page at all i.e whether the current page count is equal to totalrows i.e you have only 1 page. When a page is changed by default, the Grid makes databind call and invokes rendergridrows and that is proven to work logic.


    rubenfernande3
    Participant

    Thank you peter. Your answer gave me the key.

    I´m returning wrong total records in server side.

    Now it Works perfectly.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.