jQuery UI Widgets Forums DataTable refresh cell value

This topic contains 5 replies, has 2 voices, and was last updated by  Peter Stoev 9 years, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • refresh cell value #62962

    cpuin
    Participant

    Hi,

    I have read that some had the same problem , but i can’t find any solution here.
    I want to refresh the value of particular cell.
    From the documentation this should be done calling:

    $("#saleTable").jqxDataTable('beginCellEdit',rowIndex, 'total', true);
     $("#saleTable").jqxDataTable('endCellEdit',rowIndex, 'total', true);
    

    The main funcationality is a table with ‘quantity’, ‘price’, ‘total’ fields.
    I want when the quantity or the price cell is edited the total value to be updatted because total=quantity * price.

    This is:

    $("#saleTable").on('cellEndEdit', function (event) {
    	                                     	var args = event.args;
    	                                     	// row key
    	                                     	var rowKey = args.key;
    	                                     	// row's index.
    	                                     	var rowIndex = args.index;
    	                                     	// row's data.
    	                                     	var rowData = args.row;
    	                                     	// row's index in the data source.
    	                                     	var rowBoundIndex = args.boundIndex;
    	                                     	// column's data field.
    	                                     	var columnDataField = args.dataField;
    	                                     	// column's display field.
    	                                     	var columnDisplayField = args.displayField;
    	                                     	// cell's value.
    	                                     	var value = args.value;
    	                                     	//log changed value
    	                                     	$("#log").html(value);
    	                                     	//update source
    	                                     	if (columnDataField == 'quantity'){
    	                                     	
    	                                     	data[rowBoundIndex].quantity = value;
    	                                     	
    	                                     	}
    	                                     	if (columnDataField == 'prices'){
    	                                     		
    	                                     		data[rowBoundIndex].prices = value;
    	                                     		
    	                                     		}
    	                                     	else {
    	                                     		//do nothing
    	                                     	}
    	                                     	data[rowBoundIndex].total = data[rowBoundIndex].quantity*data[rowBoundIndex].prices;
    	                                     	$("#saleTable").jqxDataTable('beginCellEdit',rowIndex, 'total', true);
    	                                     	$("#saleTable").jqxDataTable('endCellEdit',rowIndex, 'total', true);
    	                                 	});
    
    refresh cell value #62963

    Peter Stoev
    Keymaster

    Hi cpuin,

    “beginCellEdit” opens the editor. “endCellEdit” closes the editor. If you want to set value or update a row, read about “setCellValue” and “updateRow”.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    refresh cell value #62967

    cpuin
    Participant

    Dear Peter,

    updateRow requires new values! What i need is simply update the cell(if needed row) from the source

    refresh cell value #62969

    Peter Stoev
    Keymaster

    Hi cpuin,

    Yes, it requires the Values which you want to put in the Row. That is what “updateRow” stands for. Pass the values from your data source.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    refresh cell value #62972

    cpuin
    Participant

    Thanks Peter!
    I tought there is a shorter way to update all items from the source istead to bind each of them.
    It works.

    refresh cell value #62973

    Peter Stoev
    Keymaster

    Hi cpuin,

    When there’s an update in the data source, you should notify the widget for that update. Usually, if you know what you update, you have to simply call setCellValue or updateRow, but if you do now know what’s updated in the data source, you can call updateBoundData which rebinds the widget and re-renders it.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.