grid deleteColumn and insertColumn

Hi,

I’m loading a grid dynamically according to the search condition.
like when search by April 30 columns will be loading, and May with 31 columns.

I’m using grid.deleteColumn and grid.insertColumn function to achieve it.

it works perfect after only deleteColumn
but there is a javascript error when grid data loading after deleteColumn and insertColumn.

error message:
INFO: ‘_attrs.style’ is null or not an object
line: 5054
error file: dhtmlxgrid.js

before loading grid below source code will be execute first.

	function fncSetColLabel(curYear, curMonth){
        var curMonthDays = new Date(curYear, curMonth, 0).getDate(); 
        
		var afterCount = curMonthDays;
		var colNum = oGrid.getColumnsNum();
		var beforeCount = (colNum - 2)/4;
		
		
		if( beforeCount > afterCount ){
			var j = beforeCount - afterCount;
			for( var i=0; i<j; i++ ){
				oGrid.deleteColumn(colNum-(i+1));
				oGrid.deleteColumn(colNum-(i+2));
				oGrid.deleteColumn(colNum-(i+3));
				oGrid.deleteColumn(colNum-(i+4));
				colNum -= 4;
			}
			
		}
		else if( beforeCount < afterCount ){
			var j = afterCount - beforeCount;
			for( var i=0; i<j; i++ ){
				oGrid.insertColumn(colNum+(i+1), curMonth+"-"+(beforeCount+i+1)+" TEAM", "ro",10,"na","center",null,null,null );
				oGrid.insertColumn(colNum+(i+2), curMonth+"-"+(beforeCount+i+1)+" Pgm Name", "ro",10,"na","center",null,null,null );
				oGrid.insertColumn(colNum+(i+3), curMonth+"-"+(beforeCount+i+1)+" COUNT", "ro",10,"na","center",null,null,null );
				oGrid.insertColumn(colNum+(i+4), curMonth+"-"+(beforeCount+i+1)+" SEC", "ro",10,"na","center",null,null,null );				colNum -= 4;
			}
		}
		var coInd = cInd_rank;
		for( var i=1; i<afterCount+1; i++ ){
			if( i < 10 ){
				i = "0" + i;
			}
			oGrid.setColumnLabel(coInd+1, curMonth+"-"+i+" TEAM");
			oGrid.setColumnLabel(coInd+2, curMonth+"-"+i+" Pgm Name");
			oGrid.setColumnLabel(coInd+3, curMonth+"-"+i+" COUNT");
			oGrid.setColumnLabel(coInd+4, curMonth+"-"+i+" SEC");
			coInd += 4;
		}
	}

what’s the problem?

Thanks for any reply.

Best Regards

Please, provide with a complete code of the init of your grid to reproduce the issue.

Hi,
please refer to below code.

    $(function() {
        oGrid = new dhtmlXGridObject('content');
        oGrid.imgURL = "<%= dhtmlxPath %>/dhtmlxGrid/imgs/";
        oGrid.setHeader( Type,Rank");
        oGrid.setColumnIds( "type,rank" );
        oGrid.setInitWidthsP("7,3");
        oGrid.setColAlign( "center,center" ); 
        oGrid.setColTypes( "ro,ro" ); 
        oGrid.setSkin( "dhx_skyblue" );
        oGrid.init();
        
    });
    
	$(document).ready(function() {
		fncSetColumn("${fmtInfo.currentYear}", "${fmtInfo.currentMonth}");
    	
	});

Unfortunately the issue still cannot be reproduced locally.
Please, provide a complete demo, where the issue can be reconstructed.
Here you can find a tutorial:
docs.dhtmlx.com/doku.php?id=othe … leted_demo

I’m aware that this is an ancient post but the problem remains in v4.4
For me - the only solution was to do this after i added/deleted columns:

oGrid._c_order = null;

It seems some column information is being cached there