How to use .cshtml razor file as ui-grid celltemplate? - angularjs

In my ASP.net MVC web project, I am using ANgularJS ui-grid for better data display option.
In the other razo view pages I have used partial view load
<partial name="TestPartialView" model="data.TestPartialData" />
Now in the ui-grid, in a column I also want to use the partial view.
```$scope.columns = [
{
name: 'TestColumn',
field: '..xxx',
width: '30%',
cellTemplate: 'Templates/TestPartialView.cshtml'
},] ```
But I really dont know how to do this. Also in my TestPartialView.cshtml, I need to inject a model class.
As a current alternative, I have defined the template again in the javascript file.But I want reuse the template.
Any idea?
Update:
So the above screenshot is my scenario. I will have a grid column statistics. And in the cell I will show bar chart based on some row specific model data.
Yes I have done this (as seen on the picture) with column definition.
Now the similar bar chart I have used a .cshtml file where a model class is passed and the view is loaded partially.
I want to reuse the partial view her in the grid also.

I think you can create a Controller to return your target View. And then you call this endpoint to obtain the view as the response and add it into your cellTemplate.
$http.get("https://localhost:44391/Home/GetTemplateFromPartial")
.then(function(response) {
$scope.columns = [
{
name: 'TestColumn',
field: '..xxx',
width: '30%',
cellTemplate: $sce.trustAsHtml(response.data)
}];
console.log($scope.columns);
});
The Controller will return IActionResult
public IActionResult GetTemplateFromPartial()
{
LocalMallUser user = new LocalMallUser
{
id = 1,
age = 18,
user_name = "test_user"
};
return PartialView("_SayHello", user);
}
_SayHello.cshtml:
#model WebApplication1.Models.LocalMallUser
<h1>#Model.user_name</h1>
<h2>#Model.age</h2>

Related

Angular JS Issue

I want to edit row of data table(which is coming from some rest api call,the data in datatable is populated through angular js).
My Question is I need to add one input field in each row and when I submit then all the data will go and save in the database.So can you guys help me adding input field and when I submit then how to get all the datatable data and make a JSON request.
enter image description here
Please refer the image and I need to add input field in notes column and when press save button then it should take all the 7 datas in datatable and make a json request.
javascript Code:
vm.dataTableInstance = $('.datatable-basic').DataTable({
data : priorityAttrs,
columns : [
{ data: 'priority', title : 'Priority', width : '10%' },
{ data: 'attrName', title : 'Attribute Name', width: '30%' },
{ data: 'notes', title : 'Notes' },
{ data: null, orderable : false, width:'5%', render : function(data, type, row){
return '<ul class="icons-list"><li class="delete-user text-danger-600" onclick="angular.element(this).scope().deleteAttribute(this, \''+data.attrName+'\')"><a><i class="icon-trash"></i></a></li></ul>';
}}
],
});
You can use Angular-Xeditable for add data tables. please refer this document.
install xeditable
bower install angular-xeditable
Include angular-xeditable into your project
add "xeditable" to dependencies
var app = angular.module("app", ["xeditable"]);

control flow of dhtmlx schedular for saving data via custom field

I have added custom text field in dhtmlschedular.js but
I am unable to trace the path. how can my custom field value get on controller.
or complete flow of dhtmlx for saving the data to db.
I done so far :-
lightbox: {
sections: [
{name: "description", height: 200, map_to: "text", type: "textarea", focus: true },
{ name:"prabhu", height:200, map_to:"txt1", type:"dhiraj"},
{name: "time", height: 72, type: "time", map_to: "auto"}]
dhiraj: {
render:function(sns){
return "<div class='dhx_cal_ltext' style='height:60px;'>Text <input id='txt1' name='txt1' type='text'><br/>Details <input id='calendarDetailId' name='txt2' type='text'></div>";
},
set_value:function(node,value,ev){
node.childNodes[1].value=value||"";
node.childNodes[4].value=ev.details||"";
},
get_value:function(node,ev){
ev.location = node.childNodes[4].value;
return node.childNodes[1].value;
},
focus:function(node){
var a=node.childNodes[1]; a.select(); a.focus();
}
}
};
You can add custom field without modifying sources of the component (i'd recomend avoid modifying them whenever it's possible)
If you need to add another control into the details form, you can overwrite scheduler.configuration.lightbox.sections object (in your page/script file, not in the sources)
The 'map_to' property defines property of the data object(event) to be mapped to the input.
If control should be mapped to several fields, you can use map_to:"auto" and retreive needed fields from event object manually.
The code on your page may look like following:
//defining a control
scheduler.form_blocks["dhiraj"]={
render:function(sns){
return "<div class='dhx_cal_ltext' style='height:60px;'>" +
"Text <input id='txt1' name='txt1' type='text'><br/>" +
"Details <input id='calendarDetailId' name='txt2' type='text'>" +
"</div>";
},
set_value:function(node,value,ev){
//get values from event manually
node.childNodes[1].value = ev.txt1 || "";
node.childNodes[4].value = ev.txt2 || "";
},
get_value:function(node,ev){
//assign values to event object
ev.txt1 = node.childNodes[1].value;
ev.txt2 = node.childNodes[4].value;
},
focus:function(node){
var a=node.childNodes[1]; a.select(); a.focus();
}
};
//add control to the details form
scheduler.locale.labels.section_prabhu = "";//labels for inputs are defined as 'seciton_'+inputName
scheduler.config.lightbox.sections = [
{name:"description", height:200, map_to:"text", type:"textarea" , focus:true},
{name:"prabhu", height:200, map_to:"auto", type:"dhiraj"},//here it is
{name:"time", height:72, type:"time", map_to:"auto"}
];
//init scheduler after control is defined
scheduler.init('scheduler_here',new Date(),"week");
New input will show value of 'txt1' and 'txt2' properties, as can be seen in the definition. When changes are saved, component will send all event values to the server. Custom values also will be sent.
Depending on how you handle update on the server side, you should either add custom fields to configuration of dhtmlxConnector, or retreive them from GET/POST parameters.
http://docs.dhtmlx.com/scheduler/lightbox_editors.html
http://docs.dhtmlx.com/scheduler/custom_lightbox_editor.html

How to implement jqGrid with Marionette?

I am trying to render jqGrid in my Marionette application, everything goes fine until I cannot find the way to render the pager.
I am using Handlebars that holds the template, this is the code:
hb template:
<script id='llantas_grid_tmpl' type='text/x-handlebars-template'>
<table id='llantas_catalog_list'></table>
<div id="llantas_catalog_pager">pager</div>
</script>
layout...
ui: {
table: '#llantas_catalog_list',
pager: '#llantas_catalog_pager'
},
onRender: function(){
var table = this.ui.table,
pager = this.ui.pager;
table
.jqGrid({
url: '/llantas',
datatype: "json",
colNames:['Id','Orden De Compra', 'Marca', 'Medida', 'Modelo'],
colModel:[
{name:'id',index:'id', width:55},
{name:'ordencompra',index:'ordencompra', width:90},
{name:'marca',index:'marca', width:90},
{name:'medida',index:'medida', width:90},
{name:'modelo',index:'modelo', width:90}
],
rowNum:10,
rowList:[10,20,30],
pager: '#llantas_catalog_pager',
width:1060,
height:375,
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"<h3>Catalogo llantas<h3>"
});
table
.jqGrid('navGrid','#llantas_catalog_pager',{edit:false,add:false,del:false});
}
is there a way to set the pager placeholder into the jqGrid as object?
like this:
table
.jqGrid('navGrid',pager,{edit:false,add:false,del:false});
EDIT: PLEASE ANSWER ONLY IF YOU KNOW BACKBONE MARIONETTE AND JQGRID.
In a word, No.
jqGrid does a check to make sure it is a string,
if(!$t.grid || typeof elem !== 'string') {return;}
You would need to modify the jqGrid source.
I found the way to make it work:
Once the child view (the one I was trying to render with jqGrid) has been rendered and displayed in the region of the main view I just search for the template table selector and pass the pager id inside the jqGrid pager option.
main layout...
onRender: function(){
// llantasGridView is the view holding only the template without the jqGrid (I erased everything)
var llantasGridView = new LlantasGrid.View();
// table_container is the region that will hold the llantasGridView template
this.table_container.show( llantasGridView );
// once is rendered I search for the table
var table = llantasGridView.$el.find('#llantas_catalog_list');
// here I pass the jqGrid
table
.jqGrid({
url: G.API + '/llantas',
datatype: "json",
colNames:['Id','PO'...
pager: '#llantas_catalog_pager', // pager for grid is now being displayed
...

How get html content from panel in ExtJs

I am new to ExtJs.
I have been facing a problem in panels for getting panel html content.
xtype : 'panel',
id : 'first_block',
html : '<p>Hi this is belongs to first block.</p>',
listeners : {
render : function(c) {
c.body.on('click', function() {
alert('' + this.id);
alert(Ext.getCmp('first_block').items.getAt(0).getValue());
});
}
I am not getting html content, but i am getting id like "first_block-body".
Thanks in advance.
The html property defined the HTML you want in the content of your component, in this case an Ext.Panel.
Ext.Panels create a few layers of divs in order to provide things like headers, footers, toolbars, etc.
If all you want is a div with some content, you instead want to use an Ext.Component. Components don't have a body, so a couple things change in your code.
xtype : 'component',
id : 'first_block',
html : '<p>Hi this is belongs to first block.</p>',
listeners : {
render : function(c) {
c.on('click', function() {
alert('' + this.id);
alert(this.el.dom.innerHTML);
}, this);
}
Notice that I added a third parameter to your on call, which specifies the this scope of the function call. I also edited your alert to print out the innerHTML of the element, assuming that's what you were trying to do.
UPDATE:
If you are going to use this component in a layout, it may need to be able to have its height and width set, meaning it needs to be of type box in order to be an Ext.BoxComponent.
Ext.getElementById('yourId').innerHTML

"each" method in extjs data store

So, I got a data store in my code that I'm loading in a function. In that store I want to use the each method to append each record to the body of a panel in a certain format.
What I'm trying to figure out is how to use this "each" method. Has anyone ever had to use it before? I'm relatively new to functions and programming in general so I'm trying to figure out what the "fn" and "scope" are relative to my own code.
Any help would be awesome if anyone has used this method in the ExtJS framework before.
Use Dataview for your case. Add the store and the XTemplate to your dataview and add this dataview as an item to your panel. It will be something like this:
this.store = new Ext.data.JsonStore({
url : 'myproxy.php',
baseParams : {
action : 'get_basket_files'
},
root : 'rows',
id : 'filename',
fields : ['filename', 'filepath', 'filesize', 'fileclass']
});
this.filesTemplate = new Ext.XTemplate(
'<div class="files_container"><tpl for=".">',
'<div id="{filename}" class="basket-fileblock"><div class="{fileclass}"></div>',
'<div class="filetext">{filename}</div></div> ','</tpl></div>');
this.filesTemplate.compile();
this.filesDataView = new Ext.DataView({
itemSelector : 'div.basket-fileblock', //Required
style : 'overflow:auto',
multiSelect : true,
store : this.store,
tpl : this.filesTemplate
});
var panel = new Ext.Panel({
layout : 'fit',
items : [this.filesDataView]
});
Here XTemplate is the HTML template of each of the items. Have a look at the ExtJS documentation which provides a number of examples for XTemplate.
And for an example, ExtJS each function can be used this way:
Suppose an array of items is myItems. So,
Ext.each(myItems, function(eachItem){
//Do whatever you want to do with eachItem
}, this);
It sounds like you want an Ext.DataView.
DataView use Template or XTemplate to create a rendering of data in a store.
So you instantiate a configured dataview, including a reference to your store, and the template to use, and add that DataView to your panel.

Resources