Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

id problems #328

Open
ErichNiem opened this issue Aug 27, 2015 · 5 comments
Open

id problems #328

ErichNiem opened this issue Aug 27, 2015 · 5 comments

Comments

@ErichNiem
Copy link

I am trying to get the id from my database table to show on my datatable.

So far I have tried

$properties = DB::table('property')
    ->join('vetting', 'vetting.property_id', '=', 'property.id')
    ->where('vetting_status', 'LIKE', $status)
    ->where('property.deleted_at', '=', null)
    ->join('users', 'users.id', '=', 'property.user_id')
    ->select('reference', 'property.complex_number', 'property.complex_name',     'property.street_number', 'property.street_address', 'property.province', 'property.suburb_town_city',   'property_type', 'vetting_status', 'firstname', 'lastname', 'property_id', 'user_id', 'listing_type', 'featured')
    ->get();

    return Datatable::collection(new Collection($properties))
    ->showColumns('property_id', 'reference', 'listing_type')
    ->addColumn('street_address', function($Property){
        return $Property->complex_number . ' ' . $Property->complex_name . ' ' . $Property->street_number . ' ' . $Property->street_address;
    })............

I have tried

return Datatable::collection(new Collection($properties))
->addColumn('id', function($Property){
return $Property->property_id;
})
->showColumns('reference', 'listing_type')..............

I have also tried

return Datatable::collection(new Collection($properties))
->showColumns(
['property_id' => 'ID', 'reference' => 'Reference', 'listing_type' => 'Listing Type'])
->addColumn('street_address', function($Property){
return $Property->complex_number . ' ' . $Property->complex_name . ' ' . $Property->street_number . ' ' . $Property->street_address;
}).............

my front end code is

{{ Datatable::table()
// these are the column headings to be shown
->addColumn('ID', 'Reference', 'Listing Type', 'Street Address', 'Province', 'Suburb', 'Property Type', 'User Name', 'Vetting Status', 'Action')
// this is the route where data will be retrieved
->setUrl(route('api.adminproperty', ['status' => $status]))
->setId('adminpropDatatable')
->render() }}

All give me an error
Warning: table id = adminprop

Please note, adding the id was an after thought, everything was working perfectly.

@timgws
Copy link
Collaborator

timgws commented Aug 27, 2015

You should be able to use Datatable::query, there should be no need to use a collection for this use case.

---- On Thu, 27 Aug 2015 20:49:25 +1000 [email protected] wrote ---- I am trying to get the id from my database table to show on my datatable.
So far I have tried
$properties = DB::table('property')
->join('vetting', 'vetting.property_id', '=', 'property.id')
->where('vetting_status', 'LIKE', $status)
->where('property.deleted_at', '=', null)
->join('users', 'users.id', '=', 'property.user_id')
->select('reference', 'property.complex_number', 'property.complex_name', 'property.street_number', 'property.street_address', 'property.province', 'property.suburb_town_city', 'property_type', 'vetting_status', 'firstname', 'lastname', 'property_id', 'user_id', 'listing_type', 'featured')
->get();
return Datatable::collection(new Collection($properties))
->showColumns('property_id', 'reference', 'listing_type')
->addColumn('street_address', function($Property){
return $Property->complex_number . ' ' . $Property->complex_name . ' ' . $Property->street_number . ' ' . $Property->street_address;
})............

I have tried
return Datatable::collection(new Collection($properties))

    ->addColumn('id', function($Property){

        return $Property->property_id;

    })

    ->showColumns('reference', 'listing_type')..............

I have also tried
return Datatable::collection(new Collection($properties))

    ->showColumns(

        ['property_id' => 'ID', 'reference' => 'Reference', 'listing_type' => 'Listing Type'])

    ->addColumn('street_address', function($Property){

        return $Property->complex_number . ' ' . $Property->complex_name . ' ' . $Property->street_number . ' ' . $Property->street_address;

    }).............

my front end code is
{{ Datatable::table()

// these are the column headings to be shown

->addColumn('ID', 'Reference', 'Listing Type', 'Street Address', 'Province', 'Suburb', 'Property Type', 'User Name', 'Vetting Status', 'Action')

// this is the route where data will be retrieved

->setUrl(route('api.adminproperty', ['status' => $status]))

->setId('adminpropDatatable')

->render() }}

All give me an error

Warning: table id = adminprop
Please note, adding the id was an after thought, everything was working perfectly.

Reply to this email directly or view it on GitHub.

@ErichNiem
Copy link
Author

I have just changed this and I am still getting the same error.

return Datatable::query($properties)
->showColumns('id', 'reference', 'listing_type')................

I have just tried
return Datatable::query($properties)
->showColumns('reference', 'listing_type')................

same error,

I also then realized that the error I gave you meant nothing

this is the response from ajax call

file: "C:\lamp\www\in2assets\vendor\chumper\datatable\src\Chumper\Datatable\Engines\CollectionEngine.php"
line: 246
message: "Undefined offset: 0"
type: "ErrorException"

With Collection

And

file: "C:\lamp\www\in2assets\vendor\chumper\datatable\src\Chumper\Datatable\Engines\QueryEngine.php"
line: 56
message: "__clone method called on non-object"
type: "Symfony\Component\Debug\Exception\FatalErrorException"

with Query

@timgws
Copy link
Collaborator

timgws commented Aug 31, 2015

Hey Erich,

Sorry for the short reply earlier, I was on my phone (and also on a holiday!).

Please make sure that with Datatable::query that you are passing the QueryBuilder.

$query = DB::table('property')
    ->join('vetting', 'vetting.property_id', '=', 'property.id')
    ->where('vetting_status', 'LIKE', $status)
    ->where('property.deleted_at', '=', null)
    ->join('users', 'users.id', '=', 'property.user_id')
    ->select(/* columns */)
    // NOTICE I AM NOT CALLING GET HERE! ->get(); */
    ;

    return Datatable::query($query)
        ->//etc
        ;

@ErichNiem
Copy link
Author

Hi.
No stress, this has now broken search functionality.

And order column, also not working

@timgws
Copy link
Collaborator

timgws commented Aug 31, 2015

@ErichNiem could you please let me know what version you have in your composer file?

@timgws timgws closed this as completed Aug 31, 2015
@timgws timgws reopened this Aug 31, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants