### Apache Airflow version

Other Airflow 2 version (please specify below)

### What happened

Airflow v: 2.6.0

This has been an issue since 2.4.0 for us at least. We recently did a refactor of many of our 160+ DAGs and part of that process was to remove some tags that we didn't want anymore. Unfortunately, the old tags were still left behind when we deployed our new image with the updated DAGs (been a consistent thing across several Airflow versions for us). There is also the issue that the tag filter doesn't sort our tags alphabetically.

I tried to truncate the dag_tag table, and that did help to get rid of the old tags. However, the sorting issue remains. Example:
![image](https://github.com/apache/airflow/assets/102953522/a43194a6-90f3-40dd-887e-fdfad043f200)

On one of our dev environments, we have just about 10 DAGs with a similar sorting problem, and the dag_tag table had 18 rows. I took a backup of it and truncated the dag_tag table, which was almost instantly refilled (I guess logs are DEBUG level on that, so I saw nothing). This did not initially fix the sorting problem, but after a couple of truncates, things got weird, and all the tags were sorted as expected, and the row count in the dag_tag table was now just 15, so 3 rows were removed in all. We also added a new DAG in there with a tag "arjun", which also got listed first - so all sorted on that environment.


Summary: 
1. Truncating of the dag_tag table got rid of the old tags that we no longer have in our DAGs.
2. The tags are still sorted incorrectly in the filter (see image).

It seems that the logic here is contained in `www/static/js/dags.js.` I am willing to submit a PR if I can get some guidance :)

### What you think should happen instead

_No response_

### How to reproduce

N/A

### Operating System

debian

### Versions of Apache Airflow Providers

_No response_

### Deployment

Official Apache Airflow Helm Chart

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

"""
    Parse datetime and return error message for invalid dates.
    :param v: the string value to be parsed
    :param allow_empty: Set True to return none if empty str or None
    """
    if allow_empty is True and not v:
        return None
    try:
        return timezone.parse(v)
    except (TypeError, ParserError):
        abort(400, f"Invalid datetime: {v!r}")
def node_dict(node_id, label, node_class):
    return {
        "id": node_id,
        "value": {"label": label, "rx": 5, "ry": 5, "class": node_class},
    }
def dag_to_grid(dag: DagModel, dag_runs: Sequence[DagRun], session: Session):
    """
    Create a nested dict representation of the DAG's TaskGroup and its children
    used to construct the Graph and Grid views.
    """
    query = (
        session.query(
            TaskInstance.task_id,