I ran into this problem myself and tried to fix it by modifying the vendors table. I noticed there weren't any entries for the demon trainers in the npc_vendors table, though they did have entries in the npc_vendors_template table. So I created entries in the npc_vendor table for the demon trainers and their grimoires using this query:
INSERT INTO `npc_vendor`
(`entry`, `item`, `maxcount`, `incrtime`, `ExtendedCost`)
SELECT C.`entry`, I.`entry`, 0, 0, 0
FROM `creature_template` C, `item_template` I
WHERE
C.`subname`='Demon Trainer'
AND I.`name` LIKE 'Grimoire%'
-- exclude the grimoires that train player spells
AND I.`name` NOT LIKE '%Doom%'
AND I.`name` NOT LIKE '%Inferno%'
AND I.`name` NOT LIKE '%Shadow Bolt%'
AND I.`name` NOT LIKE '%Immolate%'
AND I.`name` NOT LIKE '%Corruption%';
Unfortunately, now whenever anyone goes to buy from a demon trainer, when the store opens most visible NPCs immediately change appearance to wisps and when attempting to buy a book the "you are too far away" message appears. I reverted my changes, but I could use some guidance on how I can modify the database to fix these vendors. Or will it require a change in the server code to fix?