I don't know how to get the right results in my admin grid












0














I have 2 tables





  1. headline_attributenoutput (main table)



    and




  2. headline_attributes



    and I tried to join them so I




get all the **attribute_code** values where headline_attributeouput_id is equal to entity_id from headline_attributeoutput
table.



Now I get all the data of the join but I only need attribute_code(see expected result IMG).



This is my join :



    public function _initSelect()
{
// main tabel = > headline_attributeoutput
// join tabel = > headline_attributes
parent::_initSelect();
$this->getSelect()->joinLeft(
['headline_attributes' => $this->getTable('headline_attributes')],
'main_table.entity_id = headline_attributes.attribute_code',('*')
);
// var_dump($this);
// die();
return $this;
}


Status.php



public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$entityId = $item['entity_id'];
$attributes = $this->_gridFactory->create()->getCollection()->addFieldToSelect('attribute_code');
$output = $attributes->getData();
$item[$this->getData('name')] = json_encode($output);

}
}
return $dataSource;
}


ui_component



    <column name="attribute_code" class="HeadlineAttributenOutputModelAttributesSourcestatus">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">60</item>
<item name="label" translate="true" xsi:type="string">Attribute Code</item>
</item>
</argument>
</column>


the result I get
result



How I want it to be (inspect element)
Expected result



headline_attributenoutput table
headline_attributenoutput table



headline_attributes table
headline_attributes table










share|improve this question
























  • in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
    – Sufyan Khot
    19 hours ago










  • then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
    – mauro
    17 hours ago










  • give table prefix like headline_attributes.attribute_code
    – Sufyan Khot
    16 hours ago










  • I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
    – mauro
    15 hours ago
















0














I have 2 tables





  1. headline_attributenoutput (main table)



    and




  2. headline_attributes



    and I tried to join them so I




get all the **attribute_code** values where headline_attributeouput_id is equal to entity_id from headline_attributeoutput
table.



Now I get all the data of the join but I only need attribute_code(see expected result IMG).



This is my join :



    public function _initSelect()
{
// main tabel = > headline_attributeoutput
// join tabel = > headline_attributes
parent::_initSelect();
$this->getSelect()->joinLeft(
['headline_attributes' => $this->getTable('headline_attributes')],
'main_table.entity_id = headline_attributes.attribute_code',('*')
);
// var_dump($this);
// die();
return $this;
}


Status.php



public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$entityId = $item['entity_id'];
$attributes = $this->_gridFactory->create()->getCollection()->addFieldToSelect('attribute_code');
$output = $attributes->getData();
$item[$this->getData('name')] = json_encode($output);

}
}
return $dataSource;
}


ui_component



    <column name="attribute_code" class="HeadlineAttributenOutputModelAttributesSourcestatus">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">60</item>
<item name="label" translate="true" xsi:type="string">Attribute Code</item>
</item>
</argument>
</column>


the result I get
result



How I want it to be (inspect element)
Expected result



headline_attributenoutput table
headline_attributenoutput table



headline_attributes table
headline_attributes table










share|improve this question
























  • in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
    – Sufyan Khot
    19 hours ago










  • then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
    – mauro
    17 hours ago










  • give table prefix like headline_attributes.attribute_code
    – Sufyan Khot
    16 hours ago










  • I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
    – mauro
    15 hours ago














0












0








0







I have 2 tables





  1. headline_attributenoutput (main table)



    and




  2. headline_attributes



    and I tried to join them so I




get all the **attribute_code** values where headline_attributeouput_id is equal to entity_id from headline_attributeoutput
table.



Now I get all the data of the join but I only need attribute_code(see expected result IMG).



This is my join :



    public function _initSelect()
{
// main tabel = > headline_attributeoutput
// join tabel = > headline_attributes
parent::_initSelect();
$this->getSelect()->joinLeft(
['headline_attributes' => $this->getTable('headline_attributes')],
'main_table.entity_id = headline_attributes.attribute_code',('*')
);
// var_dump($this);
// die();
return $this;
}


Status.php



public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$entityId = $item['entity_id'];
$attributes = $this->_gridFactory->create()->getCollection()->addFieldToSelect('attribute_code');
$output = $attributes->getData();
$item[$this->getData('name')] = json_encode($output);

}
}
return $dataSource;
}


ui_component



    <column name="attribute_code" class="HeadlineAttributenOutputModelAttributesSourcestatus">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">60</item>
<item name="label" translate="true" xsi:type="string">Attribute Code</item>
</item>
</argument>
</column>


the result I get
result



How I want it to be (inspect element)
Expected result



headline_attributenoutput table
headline_attributenoutput table



headline_attributes table
headline_attributes table










share|improve this question















I have 2 tables





  1. headline_attributenoutput (main table)



    and




  2. headline_attributes



    and I tried to join them so I




get all the **attribute_code** values where headline_attributeouput_id is equal to entity_id from headline_attributeoutput
table.



Now I get all the data of the join but I only need attribute_code(see expected result IMG).



This is my join :



    public function _initSelect()
{
// main tabel = > headline_attributeoutput
// join tabel = > headline_attributes
parent::_initSelect();
$this->getSelect()->joinLeft(
['headline_attributes' => $this->getTable('headline_attributes')],
'main_table.entity_id = headline_attributes.attribute_code',('*')
);
// var_dump($this);
// die();
return $this;
}


Status.php



public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$entityId = $item['entity_id'];
$attributes = $this->_gridFactory->create()->getCollection()->addFieldToSelect('attribute_code');
$output = $attributes->getData();
$item[$this->getData('name')] = json_encode($output);

}
}
return $dataSource;
}


ui_component



    <column name="attribute_code" class="HeadlineAttributenOutputModelAttributesSourcestatus">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">60</item>
<item name="label" translate="true" xsi:type="string">Attribute Code</item>
</item>
</argument>
</column>


the result I get
result



How I want it to be (inspect element)
Expected result



headline_attributenoutput table
headline_attributenoutput table



headline_attributes table
headline_attributes table







magento2 join-table






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 hours ago









Ylgen Guxholli

688215




688215










asked yesterday









mauro

12




12












  • in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
    – Sufyan Khot
    19 hours ago










  • then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
    – mauro
    17 hours ago










  • give table prefix like headline_attributes.attribute_code
    – Sufyan Khot
    16 hours ago










  • I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
    – mauro
    15 hours ago


















  • in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
    – Sufyan Khot
    19 hours ago










  • then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
    – mauro
    17 hours ago










  • give table prefix like headline_attributes.attribute_code
    – Sufyan Khot
    16 hours ago










  • I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
    – mauro
    15 hours ago
















in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
– Sufyan Khot
19 hours ago




in $this->_gridFactory->create()->getCollection()->addFieldToSelect('entity_id') try replacing entity_id with attribute_code.
– Sufyan Khot
19 hours ago












then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
– mauro
17 hours ago




then I get this sql error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.headline_attributeoutput_id"
– mauro
17 hours ago












give table prefix like headline_attributes.attribute_code
– Sufyan Khot
16 hours ago




give table prefix like headline_attributes.attribute_code
– Sufyan Khot
16 hours ago












I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
– mauro
15 hours ago




I updated my code as you can see in the question but I still get this error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_code' in 'field list', query was: SELECT main_table.attribute_code, headline_attributes.* FROM headline_attributeoutput AS main_table LEFT JOIN headline_attributes ON main_table.entity_id = headline_attributes.attribute_code"
– mauro
15 hours ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256466%2fi-dont-know-how-to-get-the-right-results-in-my-admin-grid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256466%2fi-dont-know-how-to-get-the-right-results-in-my-admin-grid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

An IMO inspired problem

Management

Has there ever been an instance of an active nuclear power plant within or near a war zone?