How can we use custom delete confirmation message box while working with Kendo UI Grid ?
I am working on ASP.NET MVC4 application.And below is the code of my Kendo Grid.
I want to use custom confirmation message box in place of default Destroy command confirmation box.And for that i am using custom command in place of Destroy command.
But my problem is i want to fire one serer side action method in .Datasource section(just like in below code for Destroy command),but i don't know how to fire that action with Custom command.
Can any one help me out on this ?
<script id="XYZTemplate" type="text/kendo-tmpl">
#(Html.Kendo().Grid<Gts.Core.Dto.XYZDto>()
.Name("XYZItem")
.Columns(columns =>
{
columns.Bound(e => e.ID).Width(97).ClientTemplate("<span style=\"float:left\">\\#=Number\\#</span>").HtmlAttributes(new { style = "text-align:left;" });
columns.Bound(e => e.Qty).Width(30);
//columns.Command(command => { command.Destroy(); });
columns.Command(command => command.Custom("Delete").Click("deleteRow"));
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.ID))
.Read(read => read.Action("Items_Read", "Product", new { ID = "#=ID#", productId = "#=FKProductID#" }))
//.Destroy(update => update.Action("Items_Destroy", "Product"))
)
// .Events(events =>
events.DataBound("dataBoundChild").Edit("dataBoundEdit").Remove("deleteProductItemChild").Save("datasourceChange"))
.Events(events => events.DataBound("dataBoundChild").Edit("dataBoundEdit").Save("datasourceChange"))
.Editable(editable => editable
.Mode(GridEditMode.InCell)
.DisplayDeleteConfirmation(false))
.ToClientTemplate()
)
</script>
In your deleteRow function, after the you removed the row from grid, use the following code to sync the grid. The sync function will fire server-side actions accordingly depends on the changes you have made to the grid.
$("#XYZItem").data("kendoGrid").dataSource.sync();
Related
I tried to create a custom dialog using yii2-dialog, one of the kartik-v widgets. I want to create this dialog with a single button: Statistics so, using the documentation provided in the demo, I wrote the code below.
The problem is that the dialog I get has two buttons instead of one and I CAN NOT get rid of the OK button.
My questions are: is there any way to create a custom dialog using yii2-dialog with a single button? and if possible, how can I achieve this?
use kartik\dialog\Dialog;
use yii\web\JsExpression;
echo Dialog::widget([
'libName' => 'krajeeDialogCust',
'overrideYiiConfirm' => false,
'options' => [
'size' => Dialog::SIZE_LARGE,
'type' => Dialog::TYPE_SUCCESS,
'title' => 'My Dialog',
'message' => 'This is an entirely customized bootstrap dialog from scratch.',
'buttons' => [
[
'id' => 'cust-btn-1',
'label' => 'Statistics',
'action' => new JsExpression("function(dialog) {
dialog.setTitle('Title 1');
dialog.setMessage('This is a custom message for button number 1');
}")
],
]
]
]);
// button for testing the custom krajee dialog box
echo '<button type="button" id="btn-custom" class="btn btn-success">Custom Dialog</button>';
// javascript for triggering the dialogs
$js = <<< JS
$("#btn-custom").on("click", function() {
krajeeDialogCust.dialog(
"Welcome to a customized Krajee Dialog! Click the close icon on the top right to exit.",
function(result) {
// do something
}
);
});
JS;
// register your javascript
$this->registerJs($js);
And this is what I'm getting:
You need to use dialogDefaults option, according to the docs the configuration options to be setup as defaults for the bootstrap dialog (applicable when useNative is false). and the default value for useNative is false until you explicitly set to true.
Update your Dialog definition to below and override the buttons property in the dialogDefault option as the plugin sets the ok and cancel buttons by default.
echo Dialog::widget ( [
'libName' => 'krajeeDialogCust' ,
'overrideYiiConfirm' => false ,
'dialogDefaults' => [
Dialog::DIALOG_OTHER => [
'buttons' => ''
]
] ,
I'm making a customization in a PrestaShop 1.6.0.14 where I need to offer an HTML editor when the employee answers to a customer thread. This part I achieved and the I'm getting to send the HTML in the e-mail message.
My problem is to show in the history, I need to show the HTML in the history (sometimes employees send links etc..). To achieve that I need to be able to save HTML in the message field of the customer_message table. When I go to the definition of the ObjectModel (classes/CustomerMessage.php) I see this:
'message' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000),
Which is cleaning the HMTL. So I created a new file at override/classes/CustomerMessage.php with this content:
class CustomerMessage extends CustomerMessageCore
{
public function __construct($id = null) {
self::$definition['fields']['message'] = array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 65000);
parent::__construct($id);
}
}
This I believe that would override the property allowing me to save HTML in this field. But it doesn't work. Am I doing it the wrong way? If so, how can I redefine this field?
Thanks for any help
you have to use this settings:
self::$definition['fields']['message'] = array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000);
the type should be TYPE_HTML, and don't change validation isCleanHtml because it check about parts of html code that you don't want (like js, script, iframe, etc)
Let me know :)
PS: Every time that we make an override, delete the class_index.php that is stored in cache folder
I have a gird, that works normally while I'm working locally, but when I deploy the code on a server I cannot edit anymore the grid.
#(Html.Kendo().Grid<BussinessUnitDto>()
.Name("FunctionsGrid")
.AutoBind(true)
.Scrollable()
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
.DataSource(ds=>ds.Ajax().Batch(true).ServerOperation(false)
.Read("GetDeliveryUnits","DeliveryUnits")
.Create("Editing_Create", "DeliveryUnits")
.Update("Editing_Update", "DeliveryUnits")
.Destroy("Editing_Destroy", "DeliveryUnits")
.Model(model =>
{
model.Id(m => m.UnitID);
})
)
.Columns(c =>
{
c.Bound(e => e.UnitName);
c.Command(com => com.Destroy());
}
))
If I'm looking with FireBug for example, I see that the input for editing cell is not created.
Does anyone know why this behaviour?
Thank you :)
How to show the validation errors in a form in a pop dialogue box?Instead of showing it in the top of the form as a separate div, i want to show those errors in a popup dialogue box so that user clicks okay and dismiss the box.How to do this in yii?
Register your own javascript function name to the afterValidate, which is one of the options in clientOptions property in CActiveForm form class.
Your form declaration should have
'clientOptions' => array(
'validateOnSubmit' => true,
'afterValidate' => 'js:myFunc',
),
And Your form will appear like bellow
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'a-form',
'enableClientValidation' => true,
'enableAjaxValidation' => true,
'errorMessageCssClass' => 'required',
'clientOptions' => array(
'validateOnSubmit' => true,
'afterValidate' => 'js:myFunc',
),
));
?>
------Your form fields------------
------Your form fields------------
------Your form fields------------
<?php $this->endWidget(); ?>
Now, Your myFunc code:
<script type="text/javascript" charset="utf-8">
function myFunc(form, data, hasError)
{
if (hasError)
{
var errors='';
$.each(data, function(obj)
{
errors+=data[obj][0]+"\n";
});
alert(errors);
// Do what ever you want
return true;
}
}
</script>
If you enable client side validation, then you will get error message under textbox, dropdown. There is no in-built option for poping up error message.
still if you need popup error message display, then you have to do with jquery. Then add in Yii forum to help others as well :-)
Refer this link (Yii forum) for details about client side validation
You can build the HTML view yourself with a custom CFormModel and use getError() method in a modal popup.
See : http://www.yiiframework.com/doc/api/1.1/CModel#getError-detail
and : http://www.yiiframework.com/doc/api/1.1/CFormModel
I have a project written in MVC 4.
I am using kendo grid for one of my partial view
below is a part of my code for my grid
columns.Bound(p => p.BrandID).Groupable(false).Title(MyResources.LabelBrandID).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
columns.Bound(p => p.BrandNameE).Title(MyResources.LabelBrandNameE).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
columns.Bound(p => p.BrandNameA).Title(MyResources.LabelBrandNameA).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
columns.Bound(p => p.BrandID).Width(120).Title(" ").Filterable(false).Sortable(false)
.ClientTemplate(#"<img onError='BrandImgNotFound(this);' src='" + Url.Content("~/Images/Brands/") + "#=data.BrandID#.jpg' />");
columns.Template(#<text></text>).Title(" ").ClientTemplate("<input type=file name='files' onchange='dataBound(this.value)' />").Width(280).Hidden(true);
columns.Command(command => { command.Edit().Text(MyResources.EditText).CancelText(MyResources.CancelText).UpdateText(MyResources.UpdateText); command.Destroy().Text(MyResources.Delete); });
My problem is when you are uploading picture in inline editing and store it in the folder by using File.Copy,
new picture in edit mode is not appearing until you restart the application.
although the new uploaded picture is available in the folder.
Any help is appreciated.