How do you drop something or give the player something when he kills the ender dragon?

The title of this post is what I want, My datapack version is 1.20.3-1.20.4.

I tried many methods, like editing the loot table of the dragon in data/minecraft/loot_tables/entities/ender_dragon.json.

used, advancement to check if the player killed an ender dragon and give him a loot table, and even tried to use the give command to give directly to the player, but the main problem is whenever I kill the ender dragon of the end or the /summon ender_dragon the advancement don't get triggered nor it drops the loot as per data/minecraft/loot_tables/entities/ender_dragon.json

Continue to help post