jQWidgets Forums

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts

  • rubenfernande3
    Participant

    I have made another test and it seems to be the container.append the problem.


    rubenfernande3
    Participant

    Thank you peter. Your answer gave me the key.

    I´m returning wrong total records in server side.

    Now it Works perfectly.


    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.


    rubenfernande3
    Participant

    The grid is composed by 3 columns:
    -IdtipoResiduo.
    -DestipoResiduo.
    -IdgrupoResiduo

    IdtipoResiduo is the key of the grid (source-id-for=”@listaResiduos.IdtipoResiduo”). This means that when i try and update the aplication has to send to the server the value of IdtipoResiduo to perform correctly the edit action.

    When i update the column DestipoResiduo (this column is a text column) it Works perfectly.
    When i update the column IdgrupoResiduo (this column is a dropdowlist column–> column-type=”dropdownlist”) it doesnt work. The IdtipoResiduo has a wrong value. Instead of sending the value of the column IdtipoResiduo it sends the value of the row number.

    To see better the error i generate another test. This time i have in my grid 3 rows.
    If i update the column DestipoResiduo with another value i receive this in the server:

    {"IdtipoResiduo":"3452","DestipoResiduo":"description tururu","IdgrupoResiduo":"444","uid":"3452","boundindex":2,"uniqueid":"2225-18-28-28-243021","visibleindex":2,"_UID":"3452"}

    As you can see now IdtipoResiduo has a 3452 value. This is the correct value and this Works perfectly.

    Now i try to update the dropdownlist column (IdgrupoResiduo). I receive this in the server side:

    {“IdtipoResiduo”:2,”DestipoResiduo”:”description tururu”,”IdgrupoResiduo”:”grupo residuo 3″,”uid”:2,”boundindex”:2,”uniqueid”:”2225-18-28-28-243021″,”visibleindex”:2,”_UID”:2}

    Now IdtipoResiduo has a value 2. This is because im editing the 3 row. Instead of sending 3452 value it sends the row number. Is strange because the value of the dropdowlist is correct. It only fails with the id of the grid.


    rubenfernande3
    Participant

    I try to explain again. My grid has a column With type dropdownlist. I open de dropdownlist in edit mode i change The value and in That moment The server receives The data With The id of The grid With Row value instead The grid key. So the edit doesnt works because it doesnt find the correct key for updating the object.

    In other Words The edition in a grid of a column type dropdownlist doesnt works when i use tag helpers.


    rubenfernande3
    Participant

    i have been working on this…

    I dont find a a clean solution to send more than one field to the server with the grid tag helpers.
    I´m trying to use your aproach to make a crud grid but i need to send 2 fields to the server because the primary key of the database table has 2 fields.

    Im unable to make the delete operation working.
    If i cant put more than one field in the source-id how can i send more parameters to the server so my controller can get them and find the entity that has to delete.

    I have tried diferent solutions but none of them are clean.

    Do you have an example to manage crud operations with grid tag helpers when the id of the model has a composite primary key?.

    Thanx in advance.


    rubenfernande3
    Participant

    Thanks for your help Dimitar.
    I have tested and it works but if i dont declare as number the field in the source the grid doesn´t shows the currency number correctly with the ‘€’ character.
    My solution works also so i prefer to use mine.

    Anyway i have solved all the problems but is a bit hard to accomplish the job. It would be better if the data adapter recognize the ‘,’ in function of the language we indicate on it. 🙂

    For filter purposes i have solved the problem also.
    As im using this kind of solution for making paging, filter and sort http://www.jqwidgets.com/jquery-widgets-documentation/documentation/asp.net-integration/asp.net-grid-paging-sorting-filtering.htm

    I have made some changes to the buildfilters so i can manage now this decimal fields (c# solution) correctly.

    public static string BuildFilters3(int filtersCount, System.Collections.Specialized.NameValueCollection query)
    {
    //Sin en and del principio.
    var tmpDataField = “”;
    var where = ” “;
    var tmpFilterOperator = “”;
    for (var i = 0; i < filtersCount; i += 1)
    {
    var filterValue = query.GetValues(“filtervalue” + i)[0];
    var filterCondition = query.GetValues(“filtercondition” + i)[0];
    var filterDataField = query.GetValues(“filterdatafield” + i)[0];
    var filterOperator = query.GetValues(“filteroperator” + i)[0];

    //Tratamiento para los campos que son decimales para cambiar la , por el . de manera que no de error.
    switch(filterDataField)
    {
    case “ImporteTotalAutorizado”:
    filterValue = filterValue.ToString().Replace(‘,’,’.’);
    break;
    default:
    break;
    }

    if (tmpDataField == “”)
    {
    tmpDataField = filterDataField;
    where += ” ( “;
    }
    else if (tmpDataField != filterDataField)
    {
    where += “) AND (“;
    }
    else if (tmpDataField == filterDataField)
    {
    if (tmpFilterOperator == “0”)
    {
    where += ” AND “;
    }
    else
    {
    where += ” OR “;
    }
    }
    // build the “WHERE” clause depending on the filter’s condition, value and datafield.
    where += GetFilterCondition(filterCondition, filterDataField, filterValue);
    if (i == filtersCount – 1)
    {
    where += “)”;
    }
    tmpFilterOperator = filterOperator;
    tmpDataField = filterDataField;
    }
    return where;
    }


    rubenfernande3
    Participant

    Although Dimitar´s solution is a good aproach i see that in my case doesn´t work.

    My final solution for this is making the same solution but in the beforeprocessing event of the source not in the data adaptar as dimitar suggested.

    This is the source:

    var source = null;
    function sourceInicial() {
    source =
    {
    datatype: “json”,
    datafields: [

    { name: ‘FechaSolicitud’, type: ‘date’, format: “dd/MM/yyyy HH:mm:ss” },

    { name: ‘ImporteTotalAutorizado’, type: ‘number’ }

    ],
    sort: function () {
    $(“#jqxgrid”).jqxGrid(‘updatebounddata’, ‘sort’);
    },
    filter: function () {
    $(“#jqxgrid”).jqxGrid(‘updatebounddata’, ‘filter’);
    },
    beforeprocessing: function (data) {
    var returnData = {};
    data = data.d;
    totalrecords = data.count;
    returnData.totalrecords = data.count;
    returnData.records = data.data;
    rendergridrows = returnData.records;

    for (var i = 0; i < returnData.totalrecords; i++) {
    var registro = returnData.records[i];
    registro.ImporteTotalAutorizado = parseFloat(registro.ImporteTotalAutorizado.toString().replace(‘,’, ‘.’));
    returnData.records[i] = registro;
    }
    return returnData;
    },
    type: ‘get’,
    sortcolumn: ‘FechaSolicitud’,
    sortdirection: ‘desc’,
    formatdata: function (data) {
    data.pagenum = data.pagenum || 0;
    data.pagesize = data.pagesize || 15;
    data.sortdatafield = data.sortdatafield || ‘FechaSolicitud’;
    data.sortorder = data.sortorder || ‘desc’;
    data.filterscount = data.filterscount || 0;
    formatedData = buildQueryString(data);
    return formatedData;
    },
    updaterow: function (rowid, newdata, commit) {
    updaterow(newdata);
    },

    url: ‘NotificacionCompras.aspx/GetSolicitudesPendientes’
    };

    Now the problem is that when i try to find in the grid a number with ‘,’ it gives me an error. It only works with the english format with the ‘.’ character.


    rubenfernande3
    Participant

    thanks dimitar your solution works.


    rubenfernande3
    Participant

    in my opinion this is a bug of the library.


    rubenfernande3
    Participant

    i give the solution to my own problem:

    It works if i retrieve from the database the number like this 484.53 with the ‘.’ like decimal separator.
    So i have changed the culture of the aplication to english and it works.

    in reply to: export to xls export to xls #66404

    rubenfernande3
    Participant

    in firefox works perfectly. The problem comes in my old ie8.

    in reply to: export to xls export to xls #66317

    rubenfernande3
    Participant

    i´ve found the problem.
    It works without setting the heads to true.

    Excel.click(function () {
    exportinfo = $(“#jqxgrid”).jqxGrid(‘exportdata’, ‘xls’, null, false, null, null, null, ‘utf-8′);

    });

    So the problem is with the heads because the rest of the data has special spanish characters to and works perfectly.

    This is the code i use for defining the columns. The problem comes with ‘Año’ and ‘Autorización’. If i change both with ‘Ano’ and ‘Autorizacion’ it works. Any idea?

    columns: [
    { text: ‘Año’, dataField: ‘año’, width: ‘5%’ },
    { text: ‘Num.’, dataField: ‘NumeroRegistro’, width: ‘5%’ },
    { text: ‘Servicio’, dataField: ‘Servicio’, width: ‘15%’, filtertype: ‘date’, columntype: ‘datetimeinput’ },
    { text: ‘Nombre de proyecto/producto’, dataField: ‘NombreProducto’, width: ‘25%’ },
    { text: ‘Proveedor’, dataField: ‘Proveedores’, width: ‘11%’ },
    { text: ‘F. Solicitud’, dataField: ‘FechaSolicitud’, filtertype: ‘date’, cellsformat: ‘dd/MM/yyyy’, width: ‘11%’ },
    { text: ‘F. Autorización’, dataField: ‘FechaDecision’, filtertype: ‘date’, cellsformat: ‘dd/MM/yyyy’, width: ‘10%’, columntype: ‘datetimeinput’ },
    { text: ‘Imp. Autorizado’, dataField: ‘ImporteTotalAutorizado’, width: ‘11%’, cellsformat: ‘c’ },
    { text: ‘Estado’, dataField: ‘Estado’, cellsrenderer: imagerenderer, width: ‘7%’ }
    ]

    });

    in reply to: export to xls export to xls #66316

    rubenfernande3
    Participant

    thanks peter i will work on it.

    in reply to: fyltertype: date not working fyltertype: date not working #63250

    rubenfernande3
    Participant

    ok thanks Peter

Viewing 15 posts - 1 through 15 (of 18 total)