This is a migrated thread and some comments may be shown as answers.

Setting RadGrid (GridBoundColumn) to contain a list in a column

2 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 30 Dec 2013, 10:27 AM
Hi guys,

I'm currently using radgrid to show users these columns: tableName, dataSources, and dataTypes. And in the SQL database one unique dataName is attached to several dataSources/dataTypes. Currently what I can show in the table is 1 tableName and show the first dataSource attach to it in the SQL, and currently I need to show all the sources and types in a column (i.e. tableName: A, dataSource: B,C,D, dataType: E,F,G). Furthermore can I still use the sorting and filtering function for these columns?

Currently I'm using the code below (stored procedure in SQL) to obtain the dataSources by tableName. This will return dataSource1, dataSource2, and so on that is attached to the tableName. However I'm at lost on how to attach these dataSources in the column in radGrid. I searched around and I'm still not sure how to do it.

USE [table]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[getDataSources_byTableName]
    -- Add the parameters for the stored procedure here
    @tableName varchar(20)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
 
select TableAttributeName,MetadataTableAttributes.TableAttributeId,
MetadataTableAttributeValues.TableAttributeValueId,
MetadataTableAttributeValues.TableAttributeValue
into #tmp2
from  MetadataTableAttributeValues
inner join MetadataTableAttributes
on MetadataTableAttributes.TableAttributeId = MetadataTableAttributeValues.TableAttributeId
 
select distinct MetadataTables.TableName,
#tmp2.*
into #rpt2
from MetadataTables inner join MetadataTableAttributeValues
on MetadataTables.TableId = MetadataTableAttributeValues.TableId
inner join #tmp2 on MetadataTableAttributeValues.TableAttributeValueId = #tmp2.TableAttributeValueId
 
 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[caisis_tmp]') AND type in (N'U'))
DROP TABLE [dbo].[caisis_tmp]
CREATE TABLE [dbo].[caisis_tmp](
ptMRN [nvarchar](255),
dataSource1 [nvarchar](255),
dataSource2 [nvarchar](255),
dataSource3 [nvarchar](255),
dataSource4 [nvarchar](255),
)
ON [PRIMARY]
 
INSERT INTO [caisis_tmp] (ptMRN)
select distinct TableName from #rpt2
 
 
 
update [caisis_tmp]  set [caisis_tmp].dataSource1=
(SELECT TOP 1 #rpt2.TableAttributeValue from #rpt2 where [caisis_tmp].ptMRN = #rpt2.TableName);
 
update [caisis_tmp]  set [caisis_tmp].dataSource2=
(
SELECT TABLEAttributeValue from                
(SELECT ROW_NUMBER() OVER (ORDER BY TableAttributeValueID) AS RowNum, * FROM #rpt2 where #rpt2.TableAttributeName='dataSource' and  [caisis_tmp].ptMRN = #rpt2.tableName) sub
WHERE RowNum = 2
)
 
 
update [caisis_tmp]  set [caisis_tmp].dataSource3=
(
SELECT TABLEAttributeValue from
(SELECT ROW_NUMBER() OVER (ORDER BY TableAttributeValueID) AS RowNum, * FROM #rpt2 where #rpt2.TableAttributeName='dataSource' and [caisis_tmp].ptMRN = #rpt2.tableName) sub
WHERE RowNum = 3
)
 
 
update [caisis_tmp]  set [caisis_tmp].dataSource4=
(
SELECT TABLEAttributeValue from
(SELECT ROW_NUMBER() OVER (ORDER BY TableAttributeValueID) AS RowNum, * FROM #rpt2 where #rpt2.TableAttributeName='dataSource' and [caisis_tmp].ptMRN = #rpt2.tableName) sub
WHERE RowNum = 4
)
 
 
select * from [caisis_tmp]
where ptMRN = @tableName
 
drop table [caisis_tmp],#tmp2,#rpt2
END

Thank you so much :)

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 02 Jan 2014, 09:48 AM
Hello Albert,

You can use GridTemplateColumns and place your logic inside their ItemTemplates. Another possible scenario could be to use NestedHierarchyTemplates:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/hierarchy-with-templates/defaultcs.aspx

You can set the field which the column will be sorted upon using its SortExpression property and you can also handle its filter operation manually:
http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Albert
Top achievements
Rank 1
answered on 02 Jan 2014, 03:03 PM
Hi Eyup,

Thank you very much for your help. This looks very promising, I will explore this template and update you soon.

Warm Regards,
Albert
Tags
Grid
Asked by
Albert
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Albert
Top achievements
Rank 1
Share this question
or