jQuery UI Widgets Forums Grid Selectedrowindex is -1 and id is undefined

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 8 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • dujmovicv
    Participant

    Hi All,

    I’m trying to get the delete row function work…
    Here’s the part of the code :
    // delete row.

    $("#deleterowbutton").bind('click', function () {
    	var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');
    	var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
    	if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
    		var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
    		$("#jqxgrid").jqxGrid('deleterow', id);
    	}
    	console.log(selectedrowindex);
    	console.log(id);
    });

    looking at the console log : ‘selectedrowindex’ is always -1 and ‘id’ is : undefined which of course results that the delete function is not working…
    Here’s the deleterow function :

    id: 'RecordID',
    
    deleterow: function (rowid, commit) {
    	console.log('HERE');
    	// synchronize with the server - send delete command
    	   var data = "delete=true&" + $.param({RecordID: rowid});
    	   $.ajax({
    			dataType: 'json',
    			url: '../jqw/data.php',
    			cache: false,
    			data: data,
    			success: function (data, status, xhr) {
    			   // delete command is executed.
    			   commit(true);
    			},
    			error: function(jqXHR, textStatus, errorThrown)
    			{
    				commit(false);
    				console.log(data);
    			}
    		});							
    }

    What am I doing wrong here? Thanks in advance.


    Peter Stoev
    Keymaster

    Hi dujmovicv,

    It’s -1 when a row is not selected. If you don’t use row selection or you use row selection and no row is selected, it will always be -1. id is undefined because you pass -1 to getrowid. When you pass invalid params, the function will return undefined or null.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.