jQuery UI Widgets Forums DataTable setCellValue throwing error this.editColumn is null

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

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

  • mrallaris
    Participant

    Hello,

    I have a simple datatable and when a cell is edited I want to update another cell in that row. My code seems to work in that the calculated cell is being updated but Firebug is giving me the error this.editColumn is null on the line
    $(“#headertable”).jqxDataTable(‘setCellValue’, args.index, ‘estCost’, est);

    Error Message

    Here is my code …

    <head>
    
        <link rel="stylesheet" href="../scripts/JQwidgets/jqwidgets/styles/jqx.base.css" type="text/css" />
        <link rel="stylesheet" href="../scripts/JQwidgets/jqwidgets/styles/jqx.ui-smoothness.css" type="text/css" />
        <script type="text/javascript" src="../scripts/JQWidgets/scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxinput.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxtabs.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxpanel.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxdatatable.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxtooltip.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="../scripts/JQWidgets/jqwidgets/jqxdropdownlist.js"></script>
    
    	<script type="text/javascript">
    
                $(document).ready(function () {
    
    		$(".input_text").jqxInput({height: 25, width: 200, theme: 'ui-smoothness'});
    
    		$('#jqxtabs').jqxTabs({ width: 1120, height: 750, theme: 'ui-smoothness' });
    
    		$("#jqxpanel").jqxPanel({ width: 1100, height: 500 });
    
    		var headerTable = new Array();
    
    		var headerSource = {
    			localData: [
    				{laborType: "Quoted Hours", rate: "$125.00", estHours: "", estCost: "", actHours: "", actCost: ""}, 
    				{laborType: "Regular Hours", rate: "$20.00", estHours: "", estCost: "", actHours: "", actCost: ""},
    				{laborType: "Overtime x 1.5", rate: "$40.00", estHours: "", estCost: "", actHours: "", actCost: ""},
    				{laborType: "Overtime x 2", rate: "$80.00", estHours: "", estCost: "", actHours: "", actCost: ""}
    			],
    			dataType:  "array",
    			dataFields: [
    				{ name: "laborType", type: 'string' },
    				{ name: "rate", type: 'float' },
    				{ name: "estHours", type: 'float' },
    				{ name: "estCost", type: 'float' },
    				{ name: "actHours", type: 'float' },
    				{ name: "actCost", type: 'float' }
    			]
    		};
    
    		var headerDataAdapter = new $.jqx.dataAdapter(headerSource);
    
    		$("#headertable").jqxDataTable({
    			pageable: false,
    			editable: true,
    			showAggregates: true,
    			editSettings: { saveOnPageChange: true, saveOnBlur: true, saveOnSelectionChange: true, cancelOnEsc: true, saveOnEnter: true, editSingleCell: true, editOnDoubleClick: true, editOnF2: true },
    			source: headerDataAdapter,
    			columns: [
    				{ text: 'Labour Type', dataField: 'laborType', width: 200, editable: false },
    				{ text: 'Labour Rate', dataField: 'rate', width: 140, cellsFormat: "c2", align: 'right', cellsAlign: 'right' },
    				{ text: 'Estimated Hours', dataField: 'estHours', width: 140, cellsFormat: "d2", align:'right', cellsAlign: 'right', aggregates: ['sum'], aggregatesrenderer:function(summaryData){ return summaryData['sum'];} },
    				{ text: 'Estimated Cost', dataField: 'estCost', width: 140, editable: false, cellsFormat: "c2", align:'right', cellsAlign: 'right', aggregates: ['sum'], aggregatesrenderer:function(summaryData){ return summaryData['sum'];} },
    				{ text: 'Actual Hours', dataField: 'actHours', width: 140, cellsFormat: "d2", align:'right', cellsAlign: 'right', aggregates: ['sum'], aggregatesrenderer:function(summaryData){ return summaryData['sum'];} },
    				{ text: 'Actual Cost', dataField: 'actCost', width: 140, editable: false, cellsFormat: "c2", align:'right', cellsAlign: 'right', aggregates: ['sum'], aggregatesrenderer:function(summaryData){ return summaryData['sum'];} }
    			]
    		});
    
    		$('#headertable').on('cellValueChanged', function (event) {
    
    			var args = event.args;
    			var est = args.row['rate'].replace("$","") * args.row['estHours'];
    			var act = args.row['rate'].replace("$","") * args.row['actHours'];
    			$("#headertable").jqxDataTable('setCellValue', args.index, 'estCost', est);
    			$("#headertable").jqxDataTable('setCellValue', args.index, 'actCost', act);
    		});
                });
    
            </script>

    Peter Stoev
    Keymaster

    Hi mrallaris,

    The problem here is that inside an event handler which is raised when a cell value is changed, you change the cell’s value which raises the event handler again and again.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    mrallaris
    Participant

    Thank you for your explanation. How do I edit a cell after it has been changed without entering into this loop? Also, is there anyway to determine which cell was edited? I’ve seen some posts reference args.datafield but that variable doesn’t seem to be available in the datatable event.

    Thanks!

    Matt


    Peter Stoev
    Keymaster

    Hi Matt,

    – There’s no option to determine which cell is edited. It is possible to determine which row is edited.
    – in cellEndEdit it is ok to call setCellValue: http://jsfiddle.net/4c3pbesa/ because it will not be raised when you call it.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.