Build Your Admin Panel Without CSS or HTML

Build Your Admin Panel Without CSS or HTML

by Adeyinka Adegbenro

An admin panel usually refers to the set of tools available to the administrator of a web application for overseeing the app. The administrator is usually an owner or superuser who has permission to create, edit and delete certain components of a web page normally hidden from a regular user. The admin panel usually provides all the settings and tools used for system administration.

It’s not uncommon for web apps with sophisticated, complex, and beautiful user interfaces to have pretty bland admin panels. This is because the admin panel is hidden from the app's primary users and usually isn’t considered a priority. They’re also not very much fun to build because of the amount of repetitive work that goes into creating one.

In cases like this, developers would benefit from a tool that makes the process of building an admin panel easy without the need to write code. This would of course drastically reduce the amount of time and number of developers needed to work on building the admin panel. This is where Appsmith comes in.

Appsmith is an open-source framework that helps developers build dashboards, workflows, pages, and CRUD apps with little to no code. You can connect to APIs or databases like MongoDB, PostgreSQL, or MYSQL, as well as get access to charts, widgets, and other customization tools for building a UI.

In this article, you’ll learn how to set up Appsmith locally. You’ll create a new application, connect an API to it, and build an example admin panel using widgets and pages.

Getting Started with Appsmith

To begin, you'll need to sign up for Appsmith (it's free!), if you don’t already have an account. You can also deploy a Docker image on a server. For the purposes of this tutorial, you’re going to create a local instance of Appsmith using Docker.

  1. Read the instructions here to set this up for your operating system.
  2. Visit localhost in your browser to see the local version of Appsmith.
  3. Create a local account to log in.
  4. Click Create New to create a new application and name it Posts Admin Panel. This takes you to an empty workspace with a sidebar.
  5. On the sidebar, you should see items like Pages, API, and DB Queries in a folder-like structure. Under Pages, a new page, Page1, already exists. Rename it as All Posts.

Creating an application in Appsmith

Connect to a Data Source

To work with Appsmith, you need a data source. This can be in the form of an API or a database. Appsmith supports MongoDB, MySQL, and PostgreSQL among others.

  1. Make a connection to a database by clicking the plus icon near DB Queries on the sidebar under a page.
  2. Click New Datasource to see a list of different database options.
  3. Select your preferred database option and provide the relevant configuration details required to connect to your database server. As for connecting to APIs from Appsmith, you can hit any REST API endpoint available on the internet.

For the purposes of this guide, we'll connect to a fake API service called JSON Placeholder.

  1. On the sidebar, under All Posts, click on the plus icon near APIs. Click Create New, and you should see a new API page.
  2. On the upper left corner, change the API name from Api1 to all_posts and paste https://jsonplaceholder.typicode.com/posts as the URL.
  3. Click RUN to test run the API. In the Response Body section, you should see some data. This is the data you’ll display on the All Posts page in the coming section.

All Posts API data

Create the First UI View

Go to the previously created page All Posts. On this page, you’ll display a list of posts on a table using the Table Widget.

  1. Add a table to the page by clicking on the plus icon near Widgets.
  2. Drag and drop Table to the page workspace.
  3. Click the gear icon to configure the table.
  4. Change the table name from table1 to post_table.
  5. In the Table Data section, erase the dummy data and paste {{all_posts.data}} into it. This will pull data from the all_posts API you set up in the previous section.

Now you should see all of the posts on the table, with their respective columns and rows. The table comes with filtering, pagination, sorting, and a search bar.

Table with All Posts

Next, add a button that will create a new post. Once the button is clicked, you want it to open a new page that contains a form for creating a new post.

  1. Drag the BUTTON widget to the bottom of the table and label it Add New Post.
  2. Click the gear icon of the button, in the ACTIONS section.
  3. Click the onClick dropdown and choose Navigate to. The Page Name box should appear.
  4. Type in New Post as the page name.

Placing a button under a table in Appsmith

Create the Second UI View

In this section, you’ll create a New Post page.

  1. Create a new page and rename it New Post.
  2. Go back to the All Posts page. You should notice that clicking the Add New Post button takes you to the New Post page. On this page, you’ll create a form that can be used for adding new posts.
  3. Drag the Form widget to the workspace.
  4. Rename the form text Create Post.
  5. Click the gear icon on the form and change the name from form1 to new_post_form.
  6. Add a Text widget and label it User ID:.
  7. Drag the Input widget in front of it and change its name from input1 to user_id.
  8. Set the data type as Number and toggle the Required checkbox as checked.
  9. On the next row, add a Text widget and label it Title:.
  10. Drag the *Input widget in front of it and rename it title.
  11. On the next row, add a Text widget and label it Body:.
  12. Drag the Rich Text Editor widget in front of it and rename it body.

A completed form on Appsmith

CRUD Records in UI

In this section, you'll see how to configure the application to add and delete records using the fake API.

Adding Records

The form has two buttons at the bottom that controls how the form works:

  • Reset clears the form of filled-in data.
  • Submit is meant to handle the submission of the form.

To configure Submit to submit the form data, follow these steps:

  1. Click the gear icon on Submit.
  2. Go to the Actions section.
  3. Select onClick and choose the action Call an API.
  4. Select Create API. This takes you to the API interface.

Define the API that adds posts in this section by doing the following:

  1. Change the API name from Api1 to create_post.
  2. Change the method from GET to POST and paste the URL https://jsonplaceholder.typicode.com/posts.
  3. On the Body tab, define the JSON that will be sent to the fake API:
{
"userId": "{{new_post_form.data.user_id}}",
"title": "{{new_post_form.data.title}}",
"body": "{{new_post_form.data.body}}"
}

In the above sample, new_post_form refers to the form you created in the New Post page, while .data refers to the form's filled-in values.

Appsmith allows you to access all the data on the form by referring to the widget's unique name. To see the data being sent:

  1. Go to the new_post_form, fill in the table with data, and submit it.
  2. Navigate to _New Post > APIs > createpost on the sidebar.
  3. Click the Request tab. You should see the last sent request body and how the data variables previously defined are now substituted with the real values you just entered when you submitted the form.

A create_post request

You've now configured the form's Submit button to call the create_post API when the form is submitted. You can also define the action to take after submission. To do this:

  1. Go to the New Post page and click the gear icon on the Submit button.
  2. Click onSuccess.
  3. Select the action Navigate to.
  4. In the page box, type in All Posts. This means that when the form submission is successful, you want the page to redirect to the All Posts Page.
  5. Test this by filling in the form with data and submitting it. The page should redirect to the All Posts page.

Settings for the Submit button

Delete Records

To demonstrate how to delete a post using the Appsmith tools, go to the All Posts page and add a Delete button to the last column of the post_table:

  1. Click the table's gear icon and click Add a new column.
  2. Rename the column Action.
  3. Click the gear for the new column and change the Column Type to Button. Rename the button label as Delete.
  4. Change the button colour to Red.

Let's define a new API called delete_post.

  1. On the sidebar, under All Posts, create a new API and name it delete_post.
  2. Change the API method to DELETE and paste the URL as https://jsonplaceholder.typicode.com/posts/{{post_table.selectedRow.id}}. {{post_table.selectedRow.id}} refers to the post_table on the All Posts page, while selectedRow.id refers to id of the selected row about to be deleted from the table.
  3. Go back to the post_table settings and click the gear icon for the column Action.
  4. In the onClick section, select the Call an API action from the dropdown and select the delete_post API.
  5. In the onSuccess section, select the action Show message, then type in Post Successfully deleted! in the message box.
  6. Choose Success as the type.
  7. In the onError section, select the action Show message, then type in Failed to delete Post! in the message box.
  8. Choose Error as the type.

The Delete button settings

Clicking the Delete button would send an API request using delete_post and then show the success message.

Of course, the selected post does not really delete since we’re using a fake API. But it does demonstrate how you would configure deletion with a real API on an admin panel.

The delete_post API

Conclusion

You've seen how easy it is to build an application on Appsmith, specifically an admin panel. This guide covered how to create an application and connect it to a database, as well as how to add and delete data. You learned how to build interactive pages, work with widgets, and customize them for your purposes.

Building an admin panel with Appsmith is a fast way to build admin tools. Check it out if you’d like to save your developers time and get internal tools launched faster.


Author Bio: Adeyinka is a software engineer based in Lagos, Nigeria, currently at BriteCore. She loves researching and writing in-depth technical content.