Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to addrow to localdata and then batch save.
04/09/2014
23:43
Avatar
HardCorps88
Member
Members
Forum Posts: 3
Member Since:
04/09/2014
sp_UserOfflineSmall Offline

I can submit my grid no problem but when adding a new row it gets the id but not the data so its null.  How can I add my new row to my local dataset then post all in a batch save? I have included my code for reference.

parameters2 = {
        
        
            EmpID: "1234",
            concatProjectTask: "Development",
            TaskId: "3",
            ActivityName: "Regular",
            Sun: 0,
            Mon: 0,
            Tue: 0,
            Wed: 0,
            Thu: 0,
            Fri: 0,
            Sat: 0,
            Sun2: 0,
            Mon2: 0,
            Tue2: 0,
            Wed2: 0,
            Thu2: 0,
            Fri2: 0,
            Sat2: 0,
            Total: 0,
        
        position: "last",
        edit: false
    }

function NewRow2() {
        var addNewRow = new Array();
        $("#grid2").jqGrid('addRowData', '6', parameters2);
      
    }

 function SaveAll2() {
        var $grid = $('#grid2'),
            editingRowId,
            myEditParam = {
                keys: true,
                oneditfunc: function (id) { editingRowId = id; },
                afterrestorefunc: function (id) { editingRowId = undefined; }
            };
        var rowid = 0;
        var localGridData = new Array();
        var rows = $('#grid2').jqGrid('getDataIDs');
        for (var i = 0; i < rows.length; i++) {
            $('#grid2').jqGrid('saveRow', rows[i], false, 'clientArray');
            var data = $('#grid2').jqGrid('getGridParam', rows[i]);
            localGridData.push(data);
        }
        var dataToSend = JSON.stringify(localGridData);
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Employee/SaveHours",
            dataType: "json",
            data: dataToSend,

            success: function (result) {
                alert("Success");
                $('#grid').trigger('reloadGrid');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                $('#' + grid[0].id + '_err').remove();
                grid.closest('div.ui-jqgrid').before(
                    '<div id="' + grid[0].id + '_err" style="max-width:' + grid[0].style.width +
                    ';"><div class="ui-state-error ui-corner-all" style="padding:0.7em;float:left;"><span class="ui-icon ui-icon-alert" ' +
                    decodeErrorMessage(jqXHR, textStatus, errorThrown) + '</span<?div<div style="clear:left"/></div>');
            }

        });
    }

08/09/2014
14:31
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Make sure that newly added row has a uniquie id. It seems yors are not.

 

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

08/09/2014
18:26
Avatar
HardCorps88
Member
Members
Forum Posts: 3
Member Since:
04/09/2014
sp_UserOfflineSmall Offline

I thought I did when I used this function?

function NewRow2() {
        var addNewRow = new Array();
        $("#grid2").jqGrid('addRowData', '6', parameters2);
      
    }

08/09/2014
19:29
Avatar
HardCorps88
Member
Members
Forum Posts: 3
Member Since:
04/09/2014
sp_UserOfflineSmall Offline

Fixed my save issue up to a point.  Corrected code in my batch save but...when clicking my save button I can only get my current rows not my newrow I added.  I see all the ID's but not sure how to get my new row added to the batch or 'clientArray' in order to save.  In addition how do I add the Id's of each row including the new row to the batch?

parameters2 = {
        rowid: 'new_row',
        initdata:{
            EmpID: "1234",
            concatProjectTask: "Development",
            TaskId: "3",
            ActivityName: "Regular",
            Sun: 0,
            Mon: 0,
            Tue: 0,
            Wed: 0,
            Thu: 0,
            Fri: 0,
            Sat: 0,
            Sun2: 0,
            Mon2: 0,
            Tue2: 0,
            Wed2: 0,
            Thu2: 0,
            Fri2: 0,
            Sat2: 0,
            Total: 0
       },
        position: "last",
        edit: false
    }

function NewRow2() {
       
        $("#grid2").jqGrid('addRow', parameters2);
      
    }

13/09/2014
12:55
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

 

You do not need to call saveRow, since addRowData add a data direct to the grid.

Not sure what is happen with your code -I'm very confused with your code.

 

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information