Clear values in Razor MVC EditorTemplate - asp.net-mvc-3

I want to create a Date, Time and DateTime EditorTemplate using MVC3 and Razor.
For now, let's focus on the Time (I can fix the remaining templates later).
#model DateTime?
#using MyMvcApp.Properties
#Html.DropDownListFor(model => model.Value.Hour, new SelectList(new[] {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" },
Model.HasValue ? Model.Value.Hour.ToString("D2") : "00"), null, new { style = "width: auto; margin-left: 5px;" })
:
#{
List<string> availableMinutes = new List<string>();
for (int minute = 0; minute < 60; minute += 1)
{
availableMinutes.Add(minute.ToString("D2"));
}
#Html.DropDownListFor(model => model.Value.Minute, new SelectList(availableMinutes, Model.HasValue? Model.Value.Minute.ToString("D2") : "00"), null, new { style = "width: auto" });
}
<img alt="#Resources.SelectTime" src="../../../images/icon_clock_2.gif" style="margin-right: 5px" />
<input id="clearDate" type="button" value="#Resources.Clear" class="ui-state-default" />
The point is: how do I clear values of this editor template only? I can add a script that clears the values of the ID's, but then all the editortemplates of the same type would be cleared.
So my question: how can I clear all the values (hour and minute) of this template only when the clearDate button is clicked?
Thanks in advance!

You could wrap the entire template in a div container and simply walk the DOM with jQuery in context to the clearDate button. I'm doing this from memory, but it would be something like:
$(this).parent().children().contents().find("#hourElement").val("");

Related

Save inital value of input in vuejs

I have a props that render into my child component, and i've displayed the value of props into my input. The initial value would be the
student ID
<form #submit.prevent="insertScore">
<td v-for>
<input type="text" :value="classlist.id" />
</td>
<button type="submit">save</button>
</form>
in my data function
props: ["classlists"],
data() {
return {
form: new Form({
studentId: []
})
};
},
//insertScore
How do i save my initial value into my form.studentId, and i also need this to pass into my store controller in laravel
This is my classlists props
[
{"student": "Ebony Hand", "gender": "female", "id": 1 },
{"student": "Maryse Orn", "gender": "male", "id": 2 },
{"student": "Dr. Maverick Steuber", "gender": "male", "id": 3 },
{"student": "Korbin Rutherford", "gender": "male", "id": 4 }
]
put in a created (or mounted) lifecycle method and set it there.
like so:
created(){
this.form.studentId = this.studentId (assuming thats what the prop is called)
You can use the v-model directive to create two-way data bindings on form input, textarea, and select elements.
<input v-model="message" placeholder="edit me">
To use v-model with form.studentId[n]:
form should be a data property.
form.studentId should be an array.
Then you can do the following:
<div v-for='classlist in classlists'>
<input v-model="form.studentId[classlist.id]">
</div>
data() {
form: {
studentId: []
}
}

Nativescript drop down plugin display only Object object instead of value

I'm trying to display object value in drop down, and want to get the entire object value when i select any of the value. How do I set that?
I'm trying to access the Object value to display by using "." operator like below
<dd:DropDown items="{{ raw_material_list.productName }}" selectedIndex="{{ raw_material_index }}" opened="dropDownOpened" closed="dropDownClosed" selectedIndexChanged="dropDownSelectedIndexChanged" class="dropDownStyle" />
Data which I'm passing is like below
raw_material_list = [
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
];
I need to get the result exactly like i mentioned, any help is welcome.
I have updated your playground here
Changed the display to productName in drop-down-common.js
ValueList.prototype.getDisplay = function (index) {
if (types.isNullOrUndefined(index)) {
return null;
}
if (index < 0 || index >= this.length) {
return "";
}
return this._array[index].productName;
};
P.S. You must use ValueList for the Object.
the above answer was right, but for the question the very easy and straight forward solution is
var nativescript_drop_down_1 = require("../nativescript-drop-down") //Plugin
1> modify the array list like below
raw_material_list = new nativescript_drop_down_1.ValueList([
{
"id": "44",
"created_date": "2019-04-19 12:01:13",
"activeFlag": "true",
"productType": "purchase",
"productName": "suraksha",
},
{
"id": "43",
"created_date": "2019-04-19 11:59:59",
"activeFlag": "true",
"productType": "purchase",
"productName": "vajra",
}
]);
2>to access data
let obj = viewModel.get("raw_material_list")._array[viewModel.get("raw_material_index")];
console.log("----obj-----");
console.log(obj);

foreach item in an array find largest record using mongodbcsharp driver

Suppose there is an document like:
{
"_id": "1cf2080c-ce9a-367b-93ba-dbf7b2bf8a2c",
"template_id" : "1cf2080c-ce9a-367b-93ba-dbf7b2bf8a2c",
"some_value" : 12
}
mapping to a class as Template, and given a templateid array array_id = ["aa", "bb", "cc"]
question: how can I get a Template List using mongodb C# driver2.1 up, which each item in list have largest some_value ?
for example there is a collection:
{"_id": "1", "template_id": "aa", "some_value":1}
{"_id": "2", "template_id": "aa", "some_value":2}
{"_id": "3", "template_id": "aa", "some_value":3}
{"_id": "4", "template_id": "bb", "some_value":4}
{"_id": "5", "template_id": "bb", "some_value":5}
and a template_id_array = ["aa", "bb"]
expect result is:
{"_id": "3", "template_id": "aa", "some_value":3}
{"_id": "5", "template_id": "bb", "some_value":5}
I think it would be some "aggregate" or "map-reduce" like procedure, first match result and then group by template id and then find max somevalue for each group.
I have not tested this but should work with some probable modifications
var result = new List<Template>();
foreach (var element in template_id_array)
{
var filter = builder.Eq("TemplateId", element);
var doc = await collection.Find(filter)
.SortByDescending(x => x.SomeValue)
.Limit(1)
.FirstOrDefaultAsync();
result.Add(doc);
}
Then you can serialize it to the final form:
var expectedResult = JsonConvert.SerializeObject(result);

I need to group my Data in View Laravel

{
"id": "1",
"item_quantity": "3",
"item_id": "3",
"item_color": "White",
},
{
"id": "2",
"item_quantity": "3",
"item_id": "3",
"item_color": "Black",
},
{
"id": "3",
"item_quantity": "3",
"item_id": "4",
"item_color": "White",
},
Hi guys my output in Laravel using foreach is this,
ItemId:3 ItemQuantity:3 ItemColor:White
ItemId:3 ItemQuantity:3 ItemColor:Black
ItemId:4 ItemQuantity:3 ItemColor:White
But what I need is to combine those Item with the same ID like this,
ItemID:3 ItemQuantity:3 ItemColor:White/ ItemQuantity:3 ItemColor:Black
ItemId:4 ItemQuantity:3 ItemColor:White
BTW I use Table in my View, and Foreach to display may Data.
Thank you guys.. this is Laravel 4.2
#foreach($items as $item1)
<tr>{{$item1->id}}</td>
<td>{{$item1->item_quantity}}</td>
<td>{{$item1->item_color}}</td>
#foreach($items as $item2)
#if($item1->item_id == $item2->item_id)
<td>{{$item2->item_quantity}}</td>
<td>{{$item2->item_color}}</td>
#endif
#endforeach
</tr>
#endforeach
I am not sure what is your input objet but something like this:
function group_items($items){
$groupedOutput = array();
for each($items as $item){
$key = 'id_'.$item;
if(!array_key_exists($key, $groupedOutput)){
$groupedOutput[$key] = array();
}
$groupedOutput[$key][] = $item;
}
return $groupedOutput;
}
function print_items($groupedOutput){
for each($groupedOutput as $items){
for each($items as $item){
$itemId = $item['item_id'];
$itemQuantity = $item['item_quantity'];
$itemColor = $item['item_color'];
echo "ItemID:$itemId ItemQuantity:$itemQuantity ItemColor:$itemColor/ ";
}
}
}
//To group output
$groupedOutput = group_items($items);
//To print grouped output
print_items($groupedOutput);
// OR
var_dump(json_encode($groupedOutput));

jqGrid and jqPivot 4.7: Incorrect names for pivoted columns

This sample uses jqGrid 4.6:
http://jsfiddle.net/aUDHx/1218/
As one can see, regardless of the number of aggregates, the header names are displayed correctly ("A A", "A B", etc.)
However, when I switch to version 4.7, the pivoted columns aren't named correctly when more than one aggregate is used:
http://jsfiddle.net/aUDHx/1219/
If only one aggregate is used, the headers display correctly.
Does 4.7 have a different method of specifying the header names, or is this a bug? If the latter, does an appropriate workaround exist?
This is the code for the yDimension:
yDimension: [{
dataName: 'product',
converter: function (val) {return val.replace(/\s/g, ' ');}
}],
The converter function is used to correctly format the header name. This is not required in 4.7 if you only use one aggregate, but anything more than that causes it to break.
"Gurrido" is now the new name of jqGrid.
The problem is in spaces which you use in names. jqPivot don't support currently spaces in the names. You can fix the problem by replacing the spaces to _ (underscore) for example. I described the workaround here.
By the way Gurrido jqGrid is not the only successor of free open source jqGrid with MIT licence. After starting Gurrido jqGrid some other jqGrid forks of the last free jqGrid is developing. I post my results here. I plan to publish new version probably in the current month. Another fork you can find here. One apply in the fork many changes which I make in my repository, but one make some his own changes too.
UPDATED: The problem with the labels which you described is a bug in jqGrid 4.7. By the way you don't need to use the converter in case of usage spaces in the aggregation values.
I posted the bug fix here in my jqGrid repository. You can see the results on the demo http://jsfiddle.net/OlegKi/b47ocLd7/
The demo uses the following JavaScript code
var mydata = [
{ id: "1", product: "A A", sold: "8", sold2: "8", sold3: "8", emp: "Michelle" },
{ id: "2", product: "A A", sold: "3", sold2: "8", sold3: "8", emp: "Tania" },
{ id: "6", product: "A B", sold: "1", sold2: "8", sold3: "8", emp: "Mark" },
{ id: "3", product: "A B", sold: "5", sold2: "8", sold3: "8", emp: "Tommy" },
{ id: "4", product: "B B", sold: "2", sold2: "8", sold3: "8", emp: "Dave" },
{ id: "5", product: "B B", sold: "5", sold2: "8", sold3: "8", emp: "Carol" }
];
$("#grid").jqGrid("jqPivot", mydata, {
xDimension: [
{ isGroupField: false, width: 40, dataName: "id", label: "ID" },
{ isGroupField: false, width: 80, dataName: "emp", label: "Employee" }
],
yDimension: [
{ dataName: "product" }
],
aggregates: [
{ aggregator: "sum", width: 60, member: "sold", label: "Sold" },
{ aggregator: "sum", width: 60, member: "sold2", label: "Sold 2" }
],
colTotals: true
},
{
height: "auto",
pager: "#pager",
iconSet: "fontAwesome",
resizeStop: function () {
$(this).jqGrid("setGridWidth", this.grid.newWidth, false);
},
caption: "Daily Sales"
}
);

Resources