用于ExtJS网格的MySQL UNION ALL - 需要唯一的id列

我正在使用ExtJS 3.0网格并使用MySQL从PHP生成数据。 我在 id </ code>列上设置了网格的 idProperty </ code>。 问题是我有两张表用于传入发票,一张用于具有相同列的传出发票。 我想在这两个表上创建一个UNION ALL并将结果显示在ExtJS网格中。 问题是这些表中有一些重复的id会导致ExtJS网格跳过它们。 我知道我可以做简单的UNION来跳过重复但是我需要网格中的每一行,即使它们具有相同的id。 实际上没有我可以涉及的独特数据。</ p>

有什么想法吗? 谢谢。</ p>
</ div>

展开原文

原文

I am using an ExtJS 3.0 grid and generate data from PHP using MySQL. I have setup my idProperty of the grid on the id column. The problem is that I have 2 tables for incoming invoices and one for outgoing invoices with same columns. I want to make a UNION ALL on these 2 tables and show the result into the ExtJS grid. The problem is that there are some duplicate id's coming out from these tables that causes the ExtJS grid to skip them rows. I know I can do simple UNION to skip duplicates but I need every row in the grid, even if they have the same id. There are actually no distinct data that I can relate to.

Any ideas ? Thanks.

2个回答



为什么不在 SELECT </ code>数据时向id-column添加一些前缀:</ p> \ n

 (SELECT CONCAT('in-',id)AS id,... FROM in_table)
UNION ALL
(SELECT CONCAT('out - ',id)AS id,.. 。FROM out_table)
</ code> </ pre>

您必须确保阅读器配置中 id </ code> -field的字段定义具有 正确的类型(在这种情况下是 auto </ code>或 string </ code>)。</ p>

如果你需要真正的 id </ code> 然后,更改查询以选择真正的 id </ code>:</ p>

 (SELECT CONCAT('in-',id)AS gid,id,  'in'AS type ... FROM in_table)
UNION ALL
(SELECT CONCAT('out-',id)AS gid,id,'out'AS type,... FROM out_table)
</ code> </ pre>

您的 idProperty </ code>现在将是 gid </ code>。</ p>
</ div>

展开原文

原文

Why not add some prefix to the id-column when SELECTing the data:

(SELECT CONCAT('in-', id) AS id, ... FROM in_table)
UNION ALL
(SELECT CONCAT('out-', id) AS id, ... FROM out_table)

You'll have to make sure that the field-definition for the id-field in your reader configuration has the correct type (auto or string in this case).

If you need the real id afterwards, change the query to select the real id as well:

(SELECT CONCAT('in-', id) AS gid, id, 'in' AS type ... FROM in_table)
UNION ALL
(SELECT CONCAT('out-', id) AS gid, id, 'out' AS type, ... FROM out_table)

Your idProperty will be gid now.



我相信在ExtJS中 id </ code>是可选的。 如果将其关闭,网格将为每行计算自己的唯一ID。</ p>
</ div>

展开原文

原文

I believe that id is optional in ExtJS. If you leave it off, the grid will compute its own unique ID for each row.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问