1+
2+ <script src =" ~/js/signalr/dist/browser/signalr.min.js" ></script >
3+
4+ <script >
5+ // SignalR configuration.
6+
7+ var parentHubUrl = " /parentGridHub" ;
8+
9+ var parentGridConnection = new signalR.HubConnectionBuilder ()
10+ .withUrl (parentHubUrl, {
11+ transport: signalR .HttpTransportType .LongPolling
12+ })
13+ .build ();
14+
15+ var parentGridConnectionStart = parentGridConnection .start ()
16+
17+ var childHubUrl = " /childGridHub" ;
18+
19+ var childGridConnection = new signalR.HubConnectionBuilder ()
20+ .withUrl (childHubUrl, {
21+ transport: signalR .HttpTransportType .LongPolling
22+ })
23+ .build ();
24+
25+ var childGridConnectionStart = childGridConnection .start ();
26+
27+ </script >
28+
29+ <div id =" notification-container" ></div >
30+ @( Html .Kendo ().Notification () // Notification for CRUD operations of both the child and parent Grid components.
31+ .Name (" notification" )
32+ .Height (" 30%" )
33+ .Width (" 50%" )
34+ .AppendTo (" #notification-container" )
35+ )
36+
37+ @( Html .Kendo ().Grid <Product >() // Parent Grid.
38+ .Name (" grid" )
39+ .DataSource (dataSource => dataSource
40+ .SignalR ()
41+ .AutoSync (false )
42+ .Events (events => events .RequestEnd (" onEnd" ))
43+ .Transport (tr => tr
44+ .Promise (" parentGridConnectionStart" )
45+ .Hub (" parentGridConnection" )
46+ .Client (c => c
47+ .Read (" read" )
48+ .Create (" create" )
49+ .Update (" update" )
50+ .Destroy (" destroy" ))
51+ .Server (s => s
52+ .Read (" read" )
53+ .Create (" create" )
54+ .Update (" update" )
55+ .Destroy (" destroy" ))
56+ )
57+ .Schema (schema => schema
58+ .Model (model => {
59+ model .Id (id => id .ProductID );
60+ model .Field (field => field .ProductID ).Editable (false );
61+ model .Field (field => field .ProductName );
62+ model .Field (field => field .UnitsInStock );
63+ model .Field (field => field .Discontinued );
64+ model .Field (field => field .UnitPrice );
65+ model .Field (field => field .UnitsOnOrder );
66+ })
67+ )
68+ .PageSize (10 )
69+ )
70+ .Events (events => events .DetailInit (" onDetailInit" ))
71+ .Editable (editable => editable .Mode (GridEditMode .InLine ))
72+ .ToolBar (t => t .Create ())
73+ .Columns (columns =>
74+ {
75+ columns .Bound (product => product .ProductID );
76+ columns .Bound (product => product .ProductName );
77+ columns .Bound (product => product .UnitsInStock );
78+ columns .Bound (product => product .Discontinued );
79+ columns .Bound (product => product .UnitPrice );
80+ columns .Bound (product => product .UnitsOnOrder );
81+ columns .Command (command =>
82+ {
83+ command .Edit ();
84+ command .Destroy ();
85+ });
86+ })
87+ .Pageable ()
88+ .Sortable ()
89+ .Filterable ()
90+ .Groupable ()
91+ .ClientDetailTemplateId (" OrdersTemplate" )
92+ )
93+
94+ <script type =" text/kendo" id =" OrdersTemplate" >
95+ @(Html .Kendo ().Grid < Person> () // Child Grid.
96+ .Name (" People#=ProductID#" )
97+ .Columns (columns =>
98+ {
99+ columns .Bound (o => o .PersonID );
100+ columns .Bound (o => o .Name );
101+ columns .Bound (o => o .BirthDate ).Format (" {0:d}" );
102+ columns .Command (command =>
103+ {
104+ command .Edit ();
105+ command .Destroy ();
106+ });
107+ })
108+ .ToolBar (toolbar => toolbar .Create ())
109+ .Editable (editable => editable .Mode (GridEditMode .InLine ))
110+ .Pageable ().Sortable ().Filterable ()
111+ .AutoBind (false ) // AutoBind is required to be set to false in order for the parent ID identifier to be supplemented programmatically.
112+ .DataSource (dataSource => dataSource
113+ .SignalR ()
114+ .AutoSync (false )
115+ .Events (events => events .RequestEnd (" onEnd2" ))
116+ .Transport (tr => tr
117+ .ParameterMap (" onMap" )
118+ .Promise (" childGridConnectionStart" )
119+ .Hub (" childGridConnection" )
120+ .Client (c => c
121+ .Read (" read" )
122+ .Create (" create" )
123+ .Update (" update" )
124+ .Destroy (" destroy" )
125+ )
126+ .Server (s => s
127+ .Read (" read" )
128+ .Create (" create" )
129+ .Update (" update" )
130+ .Destroy (" destroy" )
131+ )
132+ )
133+ .Schema (schema => schema
134+ .Model (model =>
135+ {
136+ model .Id (" PersonID" );
137+ model .Field (" PersonID" , typeof (int)).Editable (false );
138+ model .Field (" Name" , typeof (string));
139+ model .Field (" BirthDate" , typeof (DateTime));
140+ }))
141+ .PageSize (10 )
142+ )
143+ .ToClientTemplate ()
144+ )
145+ </script >
146+
147+ <script >
148+ var parentId; // Flag variable for Parent ID unique identifier.
149+ function onDetailInit (e ) { // Detail Init is required.
150+ var dataItem = $ (" #grid" ).getKendoGrid ().dataItem (e .masterRow );
151+ parentId = dataItem .ProductID ; // Gather the Parent id unique identifier.
152+
153+ $ (e .detailRow ).find (" .k-grid" ).getKendoGrid ().dataSource .read ();
154+ }
155+ function onMap (data , type ) {
156+ switch (type) {
157+ case " read" : {
158+ return readParameterMap (data, type, parentId)
159+ }
160+ default : {
161+ return data;
162+ }
163+ }
164+ }
165+
166+ function onEnd (e ) { // Request End for Parent Grid.
167+ if (e .type == " destroy" ) {
168+ console .log (" here" );
169+ $ (" #notification" ).getKendoNotification ().show (" Delete operation has occured for the parent Grid" , " success" )
170+ } else if (e .type == " update" ) {
171+ $ (" #notification" ).getKendoNotification ().show (" Update operation has occured for the parent Grid" , " success" )
172+ } else if (e .type == " create" ) {
173+ $ (" #notification" ).getKendoNotification ().show (" Create operation has occured for the parent Grid" , " success" )
174+ }
175+ }
176+
177+
178+ function onEnd2 (e ) { // Request End for Child Grid.
179+ if (e .type == " destroy" ) {
180+ $ (" #notification" ).getKendoNotification ().show (" Delete operation has occured for the child Grid" , " success" )
181+ } else if (e .type == " update" ) {
182+ $ (" #notification" ).getKendoNotification ().show (" Update operation has occured for the child Grid" , " success" )
183+ } else if (e .type == " create" ) {
184+ $ (" #notification" ).getKendoNotification ().show (" Create operation has occured for the child Grid" , " success" )
185+ }
186+ }
187+
188+ function readParameterMap (data , operation , id ) { // Paremeter Map handler for child Grid.
189+ return { ProductID: id };
190+ }
191+ </script >
0 commit comments