Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax help to create values list for table column

Status
Not open for further replies.

waubain

Technical User
Dec 13, 2011
200
US
I am using Tablulator 4.1, which is a pure javascript library for tables. One column of my table provides a drop down list of values. I had this working by calling the function directly from editorParams:, but I got a warning that this method is being depreciated and to use the following method.

JavaScript:
{title:"Room", field:"room", editor:"select", editorParams:{
    values:function(cell){

        //lookup values from data source

        return values;
}}},

I am having trouble adapting my method to the new method. Initially when I click on the cell, nothing happens, but if I click another cell, the list of values appears as it should and then every subsequent cell I click. . I think I must be close, but do not understand why it is not populating the list on first click.

JavaScript:
            {title:"Room", field:"room", editor:"select", editorParams:{
                values:function(cell){
                    return getroomlist();}
            }},    



        function getroomlist() {
            var file = "../textfiles/room_array.txt";  
            var rawFile = new XMLHttpRequest();
                rawFile.open("GET", file, true);
                rawFile.onreadystatechange = function ()
                {
                    if(rawFile.readyState === 4)
                    {
                        if(rawFile.status === 200 || rawFile.status == 0)
                        {       
                            var data = JSON.parse(rawFile.responseText);
                        }
                                //roomlist = {};
                                window.roomlist = data.map(function(e)
				{       
                                return e.room;
                                });
                    }
                }
                rawFile.send(null);
                return window.roomlist;   
                }
 
If I change asynchronous from true to false, then it works. But I get a message in the console stating "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience.

JavaScript:
rawFile.open("GET", file, false);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top