Search code examples
androidfirebasefirebase-realtime-databasefirebase-console

sorting in real time firebase console panel


I want to sort this data to display it in JSON arranged that's my code when I upload my own data to a realtime database

and there's an image result that I want to arrange it

  HashMap<String, Object> map = new HashMap<>();
        map.put("1_UserName", a_name);
        map.put("2_phonenumber", phonenumber);
        map.put("3_Date", currentDate);
        map.put("4_Time", currentTime);
        map.put("5_Door_acess", check_Door_acess);
        map.put("6_StructuralCabling", check_StructuralCabling);
        map.put("7_Lightening", check_Lightening);
        map.put("8_check_FireSystem", check_FireSystem);
        map.put("9_AirConditioning", check_AirConditioning);
        map.put("10_Rack_01_Network", stringcheck_Rack_01_Network);
        map.put("11_PowerSourceLine1R_01", PowerSourceLine1R01);
        map.put("12_PowerSourceLine2_R01", PowerSourceLineR01);
        map.put("13_EarthingR01", EarthingR01);
        map.put("14_ofPDUsR01", ofPDUsR01editText_String11);
        map.put("15_ofOutlets_PDUR01", ofOutlets_PDUR01editText_String11);
        map.put("16_Horizontal_VerticalR01", Horizontal_VerticalR01);
        map.put("17_PPOSWOPPR01", PPOSWOPPR01);
        

        FirebaseDatabase.getInstance().getReference().child("ammar").setValue(map);

and this image from consol enter image description here


Solution

  • The Firebase console is sorting the child keys exactly as expected. They are being sorted lexicographically, or dictionary order, by string value. It won't use the numeric values that you put at the start of each child.

    If you need them to be sorted numerically by string prefix, you should pad the numeric values with 0 so the numbers are all the same width:

            map.put("01_UserName", a_name);
            map.put("02_phonenumber", phonenumber);
            map.put("03_Date", currentDate);
            map.put("04_Time", currentTime);
            map.put("05_Door_acess", check_Door_acess);
            map.put("06_StructuralCabling", check_StructuralCabling);
            map.put("07_Lightening", check_Lightening);
            map.put("08_check_FireSystem", check_FireSystem);
            map.put("09_AirConditioning", check_AirConditioning);
            map.put("10_Rack_01_Network", stringcheck_Rack_01_Network);
            map.put("11_PowerSourceLine1R_01", PowerSourceLine1R01);
            map.put("12_PowerSourceLine2_R01", PowerSourceLineR01);
            map.put("13_EarthingR01", EarthingR01);
            map.put("14_ofPDUsR01", ofPDUsR01editText_String11);
            map.put("15_ofOutlets_PDUR01", ofOutlets_PDUR01editText_String11);
            map.put("16_Horizontal_VerticalR01", Horizontal_VerticalR01);
            map.put("17_PPOSWOPPR01", PPOSWOPPR01);
    

    Use more 0s if you expect larger numbers.