Home Forums Porto Admin Template Table: How to Check and Disallow Saving When Row is Empty?

This topic contains 1 reply, has 2 voices, and was last updated by  Support2 1 month ago. This post has been viewed 84 times

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

    mjejun
    Participant

    Hi,

    I am working with an Editable Table: https://snag.gy/Lh7ctF.jpg. And I tried adjusting the ‘Save’ action to only allow saving when the row is NOT empty. However, I still can’t get the intended result.

    Is there any other way for me to complete the checking?

    Thank you.


    #10029035

    Support2
    Keymaster

    Hello,

    Try changing the rowSave method inside the file examples.datatables.editable.js to this new code:

    rowSave: function( $row ) {
    	var _self     = this,
    		$actions,
    		values    = [],
    		isEmpty   = true;
    
    	if ( $row.hasClass( 'adding' ) ) {
    		this.$addButton.removeAttr( 'disabled' );
    		$row.removeClass( 'adding' );
    	}
    
    	$row.find('td').each(function(){
    		var $this = $(this);
    
    		if ( !$this.hasClass('actions') ) {
    			if( $this.find('input').val() != '' ) {
    				isEmpty = false;
    			}
    		}
    	});
    
    	if( isEmpty ) {
    		alert("You can´t save an empty row!");
    		return false;
    	}
    
    	values = $row.find('td').map(function() {
    		var $this = $(this);
    
    		if ( $this.hasClass('actions') ) {
    			_self.rowSetActionsDefault( $row );
    			return _self.datatable.cell( this ).data();
    		} else {
    			return $.trim( $this.find('input').val() );
    		}
    	});
    
    	this.datatable.row( $row.get(0) ).data( values );
    
    	$actions = $row.find('td.actions');
    	if ( $actions.get(0) ) {
    		this.rowSetActionsDefault( $row );
    	}
    
    	this.datatable.draw();
    },

    Please, try that and let us know if you need further assistance.

    Kind Regards,

    Rodrigo.


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