jQuery UI Widgets Forums Grid jqxGrid column server validation

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  AleksandarT 6 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • jqxGrid column server validation #97729

    AleksandarT
    Participant

    Hello,
    When editing a column in jqxGrid, i am trying to check if the value exists in the DB (doing a backend call).

    columns: [
            { text: 'ValidatedColumn', dataField: 'name', width: 300,
            	validation: function (cell, value) {
            	    $.ajax({
                        url: "/getNames?name=" + value ,
                        type: "GET",
                        dataType: 'json',
                        cache: false,
                        async: false,
                        success: function(data) {
                        	console.log(data);
                        	if (data.result == "true") {
                        		return true;
                        	}  else {
                        		return false;
                        	}
                        },
                        error: function(error) {
                          console.log(error);
                          return false;
                        }
                    });
            	}
            }]

    It goes to success and returns data.result == “true”, but the validation fails before that is done. (always returns false)
    I’ve went over some answers here on the forum, one of them says to set async to false – which doesn’t help.
    Thank you in advance

    • This topic was modified 6 years, 6 months ago by  AleksandarT.
    • This topic was modified 6 years, 6 months ago by  AleksandarT.
    jqxGrid column server validation #97741

    Peter Stoev
    Keymaster

    Hi AleksandarT,

    That return false, return true should be in the context of the validation function, not in the context of the success, error functions of the AJAX callback. You would need to create variable before the AJAX method call. Within the AJAX method call update that variable. The AJAX call should be async: false. Then as a result of the validation function, return the variable.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    https://www.jqwidgets.com

    jqxGrid column server validation #97745

    AleksandarT
    Participant

    Hello Peter,
    Your suggested solution works great for me !
    Thanks a lot and have a nice day.
    Best Regards,
    AleksandarT

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

You must be logged in to reply to this topic.