generate table head based on data; resort data by firstKey