How to assign task to user

How can I associate created tasks with users?
My idea is in the task creation form, to have a select of users. How can I do it?

Hi @bras,
You thought correctly. Here is a snippet, which shows how to do it:
Main steps of this solution:

  1. Create an array to store your users(pairs of key-label)
  2. Add a new section to the lightbox, using gantt.config.lightbox.sections .(link in the API list)
    2.1 Pass your array of users as the options parameter of the select .
    2.2 map_to with sent your selected option to the owner_id parameter of the task.
  3. Create a user column in the grid, using a template(link in the API list below) to get user_id and return label for it.
  4. In this snippet, I used getUser function to loop through the user’s array and find the label for passed user_id .

Also, if you want to assign multiple users to a single task you can see how to add jQuery chosen ( ) multiselect control, check this snippet:

Main steps of this solution:

  1. Add jQuery and plugin links to the HTML file.
  2. Create custom control logic using gantt.form_blocks[multiselect]
  3. Add this control as a lightbox section in the gantt.config.lightbox.sections

List of API for single select:
Lightbox sections
Template for column:

API for multiselect :

1 Like

Thank you for your quick response.

I might have not explained myself correctly, what I want to do is make a connection with my table “users” and get an array list from there, where the label would be their name and the key woulld be their ID.

I also need this, I have tried everything but cant connect to another table in my database.


Hi @bras,
If I understand you correctly, you have 3 tables in your database - tasks , links and users . And you want to connect users with tasks, like:
task.user_id =>
If it is, so, check please this snippet again:, here you can see how to connect tasks to users on the client-side.
In your situation, you should change the way to receiving users.
In my example, I hardcoded them:
gantt.serverList("users", [key...label]) , but you should load them from the server.
In order to load users from the server, you need some server script , which will read users from the table in the database, and return them in the server response in JSON . In the same format, as in the snippet above: [{"key":0, "label": ""}, {"key":1, "label": "Ozzy Osbourne"}, ...]) .
Unfortunately, I can’t provide you with an example of this script, because I don’t know which kind of backend you are using.
When you will have the script, in the client-side instead of hardcoding array of users, you can load them using AJAX (link in the API list below), and all should work correctly. It could look like this fragment of code:

  gantt.serverList("users", []);
  gantt.ajax.get("/users").then(function(response) {
  //responseText: [{"key":0, "label": ""}, {"key":1, "label": "Ozzy Osbourne"}, ...] 
  var users = JSON.parse(response.responseText); 
  gantt.updateCollection("users", users); 


Also, if you used some of our “How To Start” examples:
for your backend, I can provide you with a little demo, to show how it could work.

API list:
serverList :

1 Like

Hi @rafael22,
You can check the answer above(How to assign task to user). If it won’t help you, you can clarify your question, and I will provide you with answer more related to your issue.

1 Like

My problem is exactly what is stated above, I cant make the connection to the users table and retrieve them in this fashion [{"key":0, "label": ""}, {"key":1, "label": "Ozzy Osbourne"}, ...]) .

I am using Laravel with a mysql database. I have used the collumn config to add colours and arrays, but they were all hardcoded, the hard part for me here is to get the array of users with serverList.

EDIT: Thank you for your help btw!!

Hi @rafael22,
Thank you for the clarification. I’ve made a quick demo using this one as a base:

Also, I’ve used the default Users model which is created with the default laravel project ( composer create-project laravel / laravel )
In order to run the demo, you’ll need to do produce the following steps:

  1. create a new database and update connection settings in the .env file
  2. composer install
  3. php artisan migrate
  4. php artisan db: seed
  5. php artisan serve

Here is the archive with the demo:

1 Like

What a legend!!!

Thank you so much, it was driving me crazy!!!

You are better than Toy (portuguese singer)!!!

1 Like