jQWidgets Forums

jQuery UI Widgets Forums Grid Grid 'getrowdata' doesn't work!!

This topic contains 2 replies, has 2 voices, and was last updated by  jperera 10 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Grid 'getrowdata' doesn't work!! #68825

    jperera
    Participant

    Hello everyone,

    I have an issue with a grid in the deleterow function of the dataadapter…
    I’m creating the grid without datasource and this is the code:

    $("#gvHolidays").jqxGrid({
                    width: "100%",
                    height: 350,
                    theme: 'bootstrap',
                    altrows: true,
                    sortable: true,
                    selectionmode: 'singlerow',
                    pageable: true,
                    pagesize: 20,
                    enableellipsis: true,
                    columnsresize: true,
                    showtoolbar: true,
                    rendertoolbar: function (toolbar) {
                        var me = this;
                        var container = $("<div style='margin: 5px;'></div>");
                        toolbar.append(container);
                        container.append('<input id="deleteAreaScheduleHoliday" type="button" value="Delete Row" />&nbsp;&nbsp;');
                        $("#deleteAreaScheduleHoliday").jqxButton({ theme: 'bootstrap', template: "warning" });
                        $("#addAreaScheduleHoliday").on('click', function () {
                            $("#cbAreaScheduleCreateHoliday").jqxComboBox('clearSelection');
                            var offset = $("#gvHolidays").offset();
                            $("#popupWindowCreateAreaScheduleHoliday").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
                            $("#popupWindowCreateAreaScheduleHoliday").jqxWindow('open');
                        });
                        $("#deleteAreaScheduleHoliday").on('click', function () {
                            if (confirm("Are you sure do you want delete?") == false)
                                return;
                            var selectedrowindex = $("#gvHolidays").jqxGrid('getselectedrowindex');
                            var rowscount = $("#gvHolidays").jqxGrid('getdatainformation').rowscount;
                            if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                                var id = $("#gvHolidays").jqxGrid('getrowid', selectedrowindex);
                                var commit = $("#gvHolidays").jqxGrid('deleterow', id);
                                var dataAdapterHol = LoadAreaScheduleHolidays();
                                $("#gvHolidays").jqxGrid({ source: dataAdapterHol });
                            }
                        });
                    },
                    columns: [
                        { text: 'Holiday', datafield: 'HolidayM', sortable: true, rendered: tooltiprenderer },
                        { text: 'Eff Date', datafield: "EffectiveDate", sortable: true, rendered: tooltiprenderer, cellsformat: 'M/d/yyyy' },
                        { text: 'Exo. Date', datafield: "ExpireDate", sortable: true, rendered: tooltiprenderer, cellsformat: 'M/d/yyyy' }
                    ]
                });

    As you could see is a very simple grid, don’t have any extra difficulty…
    This is the code for Load the dataAdapter:

    function LoadAreaScheduleHolidays() {
                var rowindex = $('#gvAreaSchedules').jqxGrid('getselectedrowindex');
                var dataRecord = $("#gvAreaSchedules").jqxGrid('getrowdata', rowindex);
                var SchedNum = dataRecord.SchedNum;
                var DevNum = dataRecord.DevNum;
                var sourceAreaScheduleHolidays =
                    {
                        type: "POST",
                        url: '@Url.Action("LoadHolidays", "Account")',
                        data: { SchedNum: SchedNum, DevNum: DevNum },
                        dataType: "json",
                        datafields: [
                                { name: 'DayTimeFlag', type: 'bool' },
                                { name: 'DayTimeNum', type: 'int' },
                                { name: 'DevNum', type: 'int' },
                                { name: 'EffectiveDate', type: 'date', format: "M/d/yyyy h:mm tt" },
                                { name: 'ExpireDate', type: 'date', format: "M/d/yyyy h:mm tt" },
                                { name: 'HolidayM', type: 'string' },
                                { name: 'HolidayDescription', type: 'string' },
                                { name: 'SchedNum', type: 'int' },
                                { name: 'TransmitterCode', type: 'string' },
                        ],
                        beforeLoadComplete: function (records) {
                            for (var i = 0; i < records.length; i++) {
                                if (records[i].EffectiveDate != null) {
                                    var date = new Date(records[i].EffectiveDate);
                                    var mil = date.getTime();
                                    var time = parseInt(mil);
                                    records[i].EffectiveDate = new Date(parseInt(time) + new Date(time).getTimezoneOffset() * 60000);
                                }
                                if (records[i].ExpireDate != null) {
                                    var date = new Date(records[i].ExpireDate);
                                    var mil = date.getTime();
                                    var time = parseInt(mil);
                                    records[i].ExpireDate = new Date(parseInt(time) + new Date(time).getTimezoneOffset() * 60000);
                                }
                            }
                            return records;
                        },
                        addrow: function (rowid, rowdata, position, commit) {
                            var params = "{" + "'DevNum':" + DevNum + "," + "'SchedNum':" + SchedNum + "," + "'HolidayM':'" + rowdata.Holidays + "'}";
                            $.ajax({
                                type: "POST",
                                url: '@Url.Action("SaveHolidaySchedule", "Account")',
                                data: params,
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    if (data.Success == true) {
                                        $("#lbNotificationSuccess").text("Holiday Saved Successfully");
                                        $("#jqxNotificationSuccess").jqxNotification("open");
                                        commit(true);
                                    }
                                    else {
                                        $("#lbNotification").text("An error occured. " + data.Message);
                                        $("#jqxNotification").jqxNotification("open");
                                        commit(false);
                                    }
                                }
                            });
                        },
                        deleterow: function (rowid, commit) {
                            var rowData = $("#gvHolidays").jqxGrid('getrowdata', rowid);
                            var params = "{" + "'DevNum':" + DevNum + "," + "'SchedNum':" + SchedNum + "," + "'HolidayM':'" + rowdata.HolidayM + "'}";
                            $.ajax({
                                type: "POST",
                                url: '@Url.Action("DeleteHolidaySchedule", "Account")',
                                data: params,
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    if (data.Success == true) {
                                        $("#lbNotificationSuccess").text("Holiday Remove Successfully");
                                        $("#jqxNotificationSuccess").jqxNotification("open");
                                        commit(true);
                                    }
                                    else {
                                        $("#lbNotification").text("An error occured. " + data.Message);
                                        $("#jqxNotification").jqxNotification("open");
                                        commit(false);
                                    }
                                }
                            });
                        }
    
                    };
                var dataAdapterAreaScheduleHol = new $.jqx.dataAdapter(sourceAreaScheduleHolidays);
                return dataAdapterAreaScheduleHol;
    
            }

    The problem is when i invoke the method ‘deleterow’ on the datasource the i test that the call is correctly but when the program execute this line: var rowData = $(“#gvHolidays”).jqxGrid(‘getrowdata’, rowid); the program stop and never do the delete…

    Any idea please!!!

    Thanks, Jose

    Grid 'getrowdata' doesn't work!! #68833

    Peter Stoev
    Keymaster

    Hello Jose,

    “getrowdata” expects row index, not row id. These are different things. Example which shows that the method works perfectly OK when the parameters which you pass are correct – http://jsfiddle.net/jqwidgets/7pdyg/. In your future topics, use more descriptive and correct topic titles.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Grid 'getrowdata' doesn't work!! #68852

    jperera
    Participant

    Thank you very much, I’m sorry for my title, my English is not good enough then i use easy words, and in fact was my mistake but in that case don’t work for me.
    Thanks for your help!!
    Jose

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

You must be logged in to reply to this topic.