How to using custom DB tables

I’m adding this as an answer, even though it doesn’t strictly answer the question you’ve asked, but it is a means to achieve what you’re after.

As I mentioned in my comment, you can use a custom post type and post meta data to store this data, you don’t necessarily have to use the WordPress provided UI to manage the data.

When you register a post type, you can set the public argument to false, this way your post type will not be displayed in the admin menu or the front end, it is entirely up to you to provide the UI to manage this data. An example of this is the built in nav menu interface, which behind the scenes is actually another post type.

Using a post type will go a long way toward providing what you need to make this work, without having to write a lot of code to create and update your data. You can use wp_insert_post, wp_update_post and wp_delete_post to insert / update / delete your templates. The post table has a parent field you can use to assign parent templates. Posts can have associated meta data via custom fields you can use to store additional fields of data, and you can use taxonomies to further categorize or organize data.

Also note, regarding your comment:

In addition, the templates should be displayed in different way and not the way of sorting titles.

If you do choose to use the built in post type UI, you can modify the columns and sorting as you like, search this site for custom admin columns, there are several questions with examples on how to do this. You can also add meta boxes to the post edit view to provide UI for additional fields, like your html and preview.