DEV Community

debbiswas
debbiswas

Posted on

Need help in Populating HTML Table from a file

Hi All,
Here am trying to retrieve data from text file and embed them to HTML table based on some condition.

Below is the code which is written in jQuery.

Alt Text

Issue is that the resulting array after filter shows no elements with length 0

Below is the result for above code in console:
Alt Text

Expected Result:
Resulting array after filter should have filtered array.

Troubleshooting done:
If the array lineByline is assigned with array values as in Line #61 which is commented then this works.

Kindly help me here please.

Top comments (11)

Collapse
 
erellsworth profile image
Edward Ellsworth

Try putting a console.log in your filter callback function to see what values it's actually fetching and comparing from the file.

Collapse
 
debbiswasgit profile image
debbiswas • Edited

Thanks Edward for reaching out. I see that it fetches exactly same values as in text file inside filter callback. Also its datatype is string for each values

Collapse
 
erellsworth profile image
Edward Ellsworth

So, if the values are exactly the same, the filtered array wouldn't be empty. I'd try adding more to the console.log statement. For example:

console.log(value, value == "p");

If this outputs something like p, false then my guess is the value variable has a phantom space around it. You could test that with something like:

console.log('xx' + value + 'xx');

If there's a phantom space, you should see something like "xxp xx" or "xx pxx"

Thread Thread
 
debbiswasgit profile image
debbiswas

Thank you Ellsworth for your response . I tried putting above checks and see that condition return false but strangely there is no phantom space even.
Alt Text

Thread Thread
 
erellsworth profile image
Edward Ellsworth

Hmm. I'm curious, if you do console.log(lineByline) what does it display? Or maybe console.table(lineByline)?

Thread Thread
 
debbiswasgit profile image
debbiswas

thank you for your response. Attaching the response for console.log(line) , lineByline and console.table(lineByline) inn sequence.

Alt Text

Thread Thread
 
erellsworth profile image
Edward Ellsworth • Edited

I'm not sure what, but something is off about your array. Console.table is only showing the index. Unless this is a browser quirk I'm not aware of, it should be showing corresponding values.

console.table

Thread Thread
 
debbiswasgit profile image
debbiswas

Yes may be browser issue. Let me then try in different browser and check. Thanks

Collapse
 
manishfoodtechs profile image
manish srivastava

Is TXT file was a table or database? Or paragraph.... And how many such files you need to convert?

Collapse
 
debbiswasgit profile image
debbiswas

Thanks Manish. Text file will always contain one column data and only one file need to be converted.

Collapse
 
manishfoodtechs profile image
manish srivastava

May be this is not best answer but it may solve your problem.

Open your text file with ms Excel with limiting tab . You will see all your text column in first column on excel sheet.

Now, you can work on this textfile and save it either SQL or text file which will be easy to get modified results with your jQuery codes.

Ms Excel is superb program. It helped me in many cases.