Datatable undefined

I have a function for creating same datatable:
function insertTable(tname, listCol, obj){

var datatable =[];
 datatable[tname] = webix.ui({
            view:"datatable",
            scroll:"xy",
            container: "table"+tname,
            css: "webix_header_border",
            columns: listCol,
            data: obj,
            select: "column", multiselect: true,
            tooltip: true,
            resizeColumn:true,
            autoheight:true,
            autowidth:true,

        });


        var button=webix.ui({
            container: "button"+tname,
            view:"toolbar",
            elements:[
                {
                    view:"button", value:"Add column", width:150,

                    click(){
                    var grid_name = "datatable["+tname+"]";
                    addColumnToSummarytable(grid_name);

                    addDataToSummarytable(obj);
                    }
                },
                {}
            ]
        });

}
function addColumnToSummarytable(grid_name){

    const grid = $$(grid_name);
   
    const grid2 = $$("grid");

    const id = grid.getSelectedId();


    if(id){
        const conf =  grid.getColumnConfig(id);
        grid2.config.columns.push({ id:conf.id, header:conf.header });
        grid2.refreshColumns();
        grid.unselect(id);
    }else{
        webix.message("Selected column not found!");
    }
}

function addDataToSummarytable(grid_data){
$$(“grid”).parse(grid_data);
}

Datatable and button creating without problems, but const grid = $$(grid_name) → undefined after selet column in table and click on button. What was the mistake I made?

the problem is solved