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
inlinedit - saveRow modified
25/07/2009
16:36
Avatar
Janooo
Member
Members
Forum Posts: 8
Member Since:
22/07/2009
sp_UserOfflineSmall Offline

Hi Tony,
Great work, thanks a million…

I have a typical row edit situation:
You edit a line;
The server saves;
If the save is a success then update row timestamp with a new value;
If the save failed because the row got updated by another user/process
then restore the row with the new values and display a message.

The success server response:
{ "rowData" : { "timestamp":"2009-07-25 16:27:39.860" }}

The failure server response:
{ "jqGridMessage" : "The record has been changed by another process. No changes were saved.",
"rowData" : { "long_name":"Joe Black", "timestamp":"2009-01-06 12:00:01.987" }}

I had a aftersave function defined at the 'editRow'.
Well it works fine but if the 'saveRow' can handle it even better and I don't have to do anything at 'editRow'.
So, I slightly modified the 'saveRow' function and its ajax call looks like this now:

$.ajax({ url: url,
    data: tmp,
    type: "POST",
    complete: function(res, stat) {
        if (stat === "success") {
            var ret;
            if ($.isFunction(succesfunc)) { ret = succesfunc(res); }
            else ret = true;
            if (ret === true) {
                tmp = $.extend({}, tmp, tmp2);
                $($t).setRowData(rowid, tmp);
                $(ind).attr("editable", "0");
                for (var k = 0; k < $t.p.savedRow.length; k++) {
                    if ($t.p.savedRow[k].id === rowid) { fr = k; break; }
                };
                if (fr >= 0) { $t.p.savedRow.splice(fr, 1); }
               
                // start of the new code
                if (isJson(res.responseText)) {
                    var jsonResponse = eval('(' + res.responseText + ')');
                    if (jsonResponse['rowData']) $($t).setRowData(rowid, jsonResponse['rowData']);
                    if (jsonResponse['jqGridMessage']) jqgrid_message(jsonResponse['jqGridMessage']);
                }
                // end of the new code
               
                if ($.isFunction(aftersavefunc)) { aftersavefunc(rowid, res.responseText); }
            } else { $($t).restoreRow(rowid, afterrestorefunc); }
        }
    },

Here are functions required for the jqgrid_message.

function create_div(oD) {
    if (oD['div_id'] && !$('#' + oD['div_id']).length) {
        var oDiv = document.createElement('div');
        if (oD['cssText']) oDiv.style.cssText = oD['cssText'];
        if (oD['title']) oDiv.title = oD['title'];
        oDiv.id = oD['div_id'];
        document.body.appendChild(oDiv);
    }
}

function isJson(string) {
    return typeof (eval("(" + string + ")")) == 'object';
}
// or this one
jQuery.isJson = function(str) {
    if (jQuery.trim(str) == '') return false;
    str = str.replace(/\\\\./g, '@').replace(/"[^"\\\\\\n\\r]*"/g, '');
    return (/^[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]*$/).test(str);
}

function jqgrid_message(msg){
    if (!$('#jqgrid_message').length) {
        create_div({ 'div_id': 'jqgrid_message', 'cssText': 'display: none\\;', 'title': 'jqGrid Message' });
        $('#jqgrid_message').html(
            '<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>\\
            <span id="jqgrid_message_text">&nbsp;</span></p>'
        );
    }
    $('#jqgrid_message_text').html(msg);
    $('#jqgrid_message').dialog({
        bgiframe: true,
        modal: true,
        width: 450,
        buttons: {
            Ok: function() {
                $(this).dialog('destroy');
            }
        },
        close: function(event, ui) { $(this).dialog('destroy'); }
    });
}

If the modified 'saveRow' function makes sense, please, feel free to include it in the jqGrid.
I created the 'jqgrid_message' function as a jQuery modal dialog.
Maybe a jqGrid method 'message' or 'dialog'  that opens in the middle of a grid would be useful.
Just a new item on the wish list Smile

Regards,
Jano

27/07/2009
02:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

You can use the info_dialog function for this purpose. Just look in grid.common.js.

Regards

Tony

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:
31 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