Can i add multiple column from db at one table?

Can i add multiple column from db at one table?

uTrxuTrx Posts: 24Questions: 6Answers: 0
edited January 2022 in DataTables

I have some users fetching from db and shown on datatables. So far so good, every user have their name on db column called first_name. What i am asking, can i do anything to write user and first_name in one table column <th> for example

101 -> Username

Answers

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934

    Yes. Depending on when / where you are getting the user's name you can use columns.title or jQuery to set the th. You can use the jQuery statement in initComplete.

    Kevin

  • uTrxuTrx Posts: 24Questions: 6Answers: 0
    edited January 2022

    I get first name from another db like this.

    Laravel Controller

    $data = Student::select('user_id') ->distinct() ->get();
    
    $aName = \DB::connection('mysql2') ->table('users') ->select('full_name', 'user') ->get();
    
    columns:
     [
        { data: 'user_id', className: 'font-weight-bold' },
     ],
    

    How can i use one of this options to make what i am looking for. Can you do an example with my code?

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934

    Here is an example:
    http://live.datatables.net/savecude/1/edit

    The initComplete function passes in the JSON from the Ajax response. You can get the name from one of the rows or you can add an additional object to the response with the data you want.

    Kevin

  • uTrxuTrx Posts: 24Questions: 6Answers: 0

    But how can i return 2 variable on json data. For now i am using this method but i can return just one variable with this

    return Datatables::of($data)
                ->make(true);
    

    And i have do return and $aName

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    I don't know Laravel very well I'm afraid, so I suspect that you'll need to ask in a Laravel forum or Stackoverflow, but it looks to me like your JSON should contain both full_name and user properties from the above.

    Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Thanks,
    Allan

Sign In or Register to comment.