Kendo grid not displaying Clolumns data that are not include in client templete row - kendo-grid

My Isuue is,I have added kendo grid and bounded with data getting from a particular class. Then, I appended with one more column includes icons by using client row templete.
corresponding data is not displaying after I appended with one more column(client row templete.before its working absolutely fine). I need to show data in all columns.
I tried to include but failed.
My Code is-
#(Html.Kendo().Grid
(Model.Services)
.Name("SummaryGrid")
.Columns(columns =>
{
columns.Bound(c => c.Service_Name).Title("Service Name");
columns.Bound(c => c.Service_Type).Title("Service Type");
columns.Bound(c => c.Service_Resource).Title("Resource");
columns.Bound(c => c.Region).Title("Region");
columns.Bound(c => c.TotalQuantity).Title("Quantity");
columns.Bound(c => c.UnitOfMeasure).Title("Unit of Measure");
columns.Bound(c => c.TotalCost).Title("Total Cost($)");
columns.Template(e => { }).ClientTemplate(" ").Title("Actions");
})
.ClientRowTemplate(
" <td >" +
"<a href='javascript:void(0);' title='Edit' class='clsEditService'> <span class='icon-E70F blackIcon'></span></a>" + " </a>"+
"<a href='javascript:void(0);' title='Delete' class='clsDeleteService'>"+
"<span class='icon-E74D blackIcon'></span>"+" </a>"+
" </td>"
)
Expected grid to show all columns corresponding data at the end edit and delete icons as well(I am not looking for default edit and delete functionalities from kendo)

A ClientRowTemplate adds a row below your grid row. If you want a column for your edit/delete, try something like this:
columns.Template(e => {}).Title("Actions")
.ClientTemplate("#<a title='Edit' class='clsEditService'><span class='k-grid-edit icon-E70F blackIcon'></span></a> " +
"<a title='Delete' class='clsDeleteService'><span class='k-grid-delete icon-E74D blackIcon'></span></a>");
Note that if you add the classes k-grid-edit and k-grid-delete this will tell kendo to run your update and delete Ajax actions automatically, otherwise set your own events accordingly.

Related

Custom row/checkbox template for Kendo UI grid

I am trying to create a custom row template for a Kendo UI grid that includes the checkbox functionality. I have the grid created like this:
#(Html.Kendo().Grid(Model.Users)
.Name("usersGrid")
.Columns(columns =>
{
columns.Select().Width(50);
columns.Bound(c => c.UserName);
})
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false))
.ClientRowTemplate(UsersClientTemplate))
With a function to generate the row template like this:
Func<Grid<User>, string> UsersClientTemplate = (grid) =>
{
var id = Guid.NewGuid();
return #"<tr data-uid='#:uid#' role='row'>" +
"<td role='gridcell'>" +
$"<input class='k-checkbox' data-role='checkbox' type='checkbox' id={id}>" +
$"<label class='k-checkbox-label k-no-text' for={id}>​</label>" +
"</td>" +
"<td role='gridcell'>" +
"<a href='/users/details/#:data.Id#'>#:data.UserName#</a>" +
"</td>" +
"</tr>";
};
The problem is I can't figure out how to generate the unique ids for each row's template. If I don't include the id attribute on the checkbox input element and the for attribute on the checkbox label element, the checkbox/row selection doesn't work. But with the function I have above, the same id is generated for every row template and then the checkbox/row selection only works for the first row, obviously.
What is a better way to do this?
Templates are generated when the grid is built so as you have seen the id is always the same. What you want is to databind so kendo replaces the id with each record. I use my entity key with a prefix like "cb_" for checkbox:
$"<input class='k-checkbox' data-role='checkbox' type='checkbox' id='cb_#:uid#'>" +
$"<label class='k-checkbox-label k-no-text' for='cb_#:uid#'>​</label>" +

Add class to bootstrap textbox - yii2

I have a form in yii2. In that I have a input field like below.
<input type="text" class="form-control" id="productsales-<?= $i ?>-value">
It's inside a dynamic form andno coming from any model.It's just to hold some calculated value. And the idea is to calculate the values fileed by users in this field to another textbox like below -
<?= $form->field($model, 'amount')->textInput(['maxlength' => true, 'class' => 'sum']) ?>
I already have the javascript code to calculate the total amount like below -
<?php
/* start getting the total amount */
$script = <<<EOD
var getSum = function() {
var items = $(".item");
var sum = 0;
items.each(function (index, elem) {
var priceValue = $(elem).find(".sumPart").val();
//Check if priceValue is numeric or something like that
sum = (parseFloat(sum) + parseFloat(priceValue)).toFixed(2);
});
//Assign the sum value to the field
$(".sum").val(sum);
};
//Bind new elements to support the function too
$(".container-items").on("change", ".sumPart", function() {
getSum();
});
EOD;
$this->registerJs($script);
/*end getting the total amount */
?>
Please note that I have a class sum in the second textbox which comes from a model. My question is that how can I add a class(sumPart) like this(sum) in the first textbox which is not coming from a model.
Update after discussion with Insane Skull
I have a dynamic form like below
I want to calculate sum of all the entries in Value and pass it to amount.
The code of Value is -
<input type="text" class="form-control sumPart" id="productsales-<?= $i ?>-value">
The code of Amount is -
<?= $form->field($model, 'amount')->textInput(['maxlength' => true, 'class' => 'sum']) ?>
The javascript I've tried is already given above.
The problem with this code is the calculated "value" is not passing to amount textbox.
Update: A little issue
Modify JS :
$this->registerJs('
function getSum() {
var sum = 0;
var items = $(".item");
items.each(function (index, elem) {
var priceValue = $(elem).find(".sumPart").val();
sum = parseFloat(sum) + parseFloat(priceValue);
});
if(isNaN(sum) || sum.length == 0) {
sum = 0;
}
$(".sum").val(sum);
}
$(".container-items").on("change", function() {
getSum();
});
jQuery(".dynamicform_wrapper").on("afterDelete", function(e) {
getSum();
});
');
I am little unsure about the problem you are facing. If you want to add a class to a input field, you can easily do so in the class attribute of the input tag. And the class attribute does support multiple values, so you can write something like this:
<input type="text" class="form-control sumPart" id="productsales-<?= $i ?>-value">
**UPDATE -- based on comment by OP **
#Tanmay, I understand that you may not be getting the desired output. However, it should not really matter if we are rendering the fields using $form->field() or plain HTML. If the fields have the proper classes assigned, then the JS code posted by Kostas in your referenced link should work - irrespective of how the class name was added to the input field.
Can you please confirm (by using Inspect Element) if the sumPart class is actually assigned to the relevant fields once the page loads? Maybe some JS is overwriting the class attribute again?
If the classes are assigned properly, please check if there are any other JS errors in console which may prevent the sum calculation JS from working properly.

Yii2 Dynagrid: How to implement Sortable to sort the rows

In Dynagrid it is possible to use Sortable to sort the columns. I need to enable sorting rows, which should work similarly:
Is there a way to implement such sorting directly in Dynagrid or do I have to programm the sorting separately?
To enable the sorting is simple:
$('tbody').sortable();
The only problem is to save the sorting to the database. I have decided to save it after a click on a button (and not with ajax) in views/sorted-table/index.php:
if (strpos(Url::current(), 'sort') === false) {
$form = ActiveForm::begin([
'id' => 'sort-form',
]);
echo '<input type="hidden" id="field-sort" name="sort" value="">';
if (isset($sortMessage) && $sortMessage != '') {
echo '<p>' . $sortMessage . '</p>';
}
echo Html::submitButton(Icon::show('floppy-o') . 'Sortierung speichern', ['class' => 'btn btn-primary']);
ActiveForm::end();
DynagridSortAsset::register($this);
}
The positions of rows are saved in the hidden input field by jQuery:
$('.btn-primary').mousedown(function() {
var sorting = "";
$('.sortable-row').each( function (index, value) {
sorting += $(this).attr('data-id') + ':' + $(this).attr('data-sortierung') +',';
});
$('#field-sortierung').val(sorting);
});
The values are then in controller processed and saved to the database.

KendoUI-Grid, CustomCommand - enable/disable

I wants to enable/disable custom command in kendo-ui grid based on some other column.
How do i achieve that? Below is sample code
#(Html.Kendo().Grid<Model>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(a => a.Name).Width(90);
columns.Bound(a => a.Flag).Width(170);
columns.Command(commands => commands.Custom("ABC").Text("ABC").Click("ABC")).Title ("ABC").Width(130);
...
}
I want to enable/disable ABC command button based on flag value. Please help me.
You cannot do this through the command column.
I would suggest you to create template column which displays button based on your condition. How to execute conditional logic inside a template (or use external function to handle for complex logic) is covered here.
I solved the problem. Below is the sample code.
columns.Bound(a => a.Flag).ClientTemplate(
"# if(Flag == 'Value1') { #" + "<input type='button'
class='info k-button k-button- icontext' onclick='clickhere(#=parameter1#)'
value='ClickHere' />" +
"# } else { #" +
"NormalText" +
"# } #").Width(100).Title("ConditionalButton");
//JavaScript
<script type="text/javascript">
function clickhere(parameter1) {
window.location.href = '#Url.Action("Event", "Home")' +
'?parameter1=' + parameter1;
}
</script>

Ada: Writing output numbers in a file separated by a tab

Just putting part of some code here where I am writing two values to a text file.
Ada.Long_Float_Text_IO.Put (File => Output_File, Item => Out_2, Fore => 1, Aft => 4, Exp => 0);
Ada.Text_IO.Put (Output_File, " ");
Ada.Long_Float_Text_IO.Put (File => Output_File, Item => Out_3, Fore => 1, Aft => 4, Exp => 0);
I can separate these numbers Out_2 and Out_3 by a space as shown in the code. The results give (after writing more numbers in the two columns):
-75.2340 421.5700
1256.0000 15.4700
-4568.9800 -118.2800
3784.2100 0.0000
I would like to know if there is a way to specify a tab spacing so that I can have something like this in my text file:
-75.2340 421.5700
1256.0000 15.4700
-4568.9800 -118.2800
3784.2100 0.0000
So which control character produces the above alignment?
Thanks a lot...
For a tab, there’s the obsolescent ASCII.HT or Ada.Characters.Latin_1.HT.
Or you could use the Width parameter to Ada.Long_Float_Text_IO.Put and friends.
Edit: There is no Width parameter for real output! You could use a large Fore, which would effectively right-justify the output.
Instead of that intervening:
Ada.Text_IO.Put (Output_File, " ");
Call the Set_Col procedure instead, which moves the output line position to the specified column. E.g.
Ada.Text_IO.Set_Col(Output_File, 13);