Sunday, November 20, 2016

Kendo Grid Tips: Adding New Row to Kendo Gird with Enter Key Press

There were requirements to add new row to editable gird when user click on last editable cell. Using addRow() function of kendo gird we can add new row to data gird. However to use that function we need to identify the correct key stroke and correct cell to invoke addRow() function. Following code snippet shows how to add new row to grid if user press enter key on 4th column.

We can change javascript key value to modify following script to trigger on any key (e.g. if change (code == 9) you can add new row with Tab key)

    $(document).ready(function () {
        $("#MyGrid").on("keyup", "tr", function (e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            var td = $(e.target).closest('td');


            if (code == 13) {
                var tdIndex = td.index();


                if (tdIndex == 3) {
                    var grid = $("#MyGrid").data("kendoGrid");
                    grid.addRow();
                }
            }
        });
    }); 

Monday, September 5, 2016

Change XamDataGrid Cell based on values of other cells in code behind – WPF

Sometimes we have requirement to enable/disable single cell value in data grid based on the selections of other cells.

Scenario:
There were XamDataGrid which user able to add purchasing details for their warehouse. When user purchase materials from different units like (Meters, Kilograms) however user only use Yard in their manufacturing process.

If user select Yard for their unit and they get those materials from Meters, then user need to set Meter to Yard conversion automatically and freeze the conversion cell.


How to implement:
Add value change event to the Unit columns


<EventSetter Event="igEditors:ValueEditor.ValueChanged" Handler="PUOM_OnValueChanged" />

<EventSetter Event="igEditors:ValueEditor.ValueChanged" Handler="SUOM_OnValueChanged" />
Code-behind:
Based on the conditions user can add any conditions to filter values. “Conversion” is the column name contains the cell.

private void SUOM_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
   DataRecord dt = (DataRecord)xamGridLines.ActiveRecord;
   Cell cellConversion = dt.Cells["Conversion"] as Cell;
   var cellEditor = Infragistics.Windows.DataPresenter.CellValuePresenter.FromCell(cellConversion).Editor;
   cellEditor.IsReadOnly = true;
}
If user need to inactive entire column use following code snippet
private void SUOM_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    xamGridLines.FieldLayouts[0].Fields["Conversion"].Settings.AllowEdit = false;
    xamGridLines.ActiveRecord.FieldLayout.Fields["Conversion"].Settings.AllowEdit = false;
}


Sunday, January 17, 2016

Bower Tips: Fix Syntax Error in bower.json

Bower is a famous package manager in now a days.
Sometimes while restoring the packages it gives “Malformed bower.json” error. 
Once error occurred most of times we only consider the bower config file which added in to the project. However while we adding package to the project it creates its own bower.json file and .bower.json file inside the package. If one of those files are malformed then it gives same malformed error while restoring the packages or while restoring dependencies. Due to that reason we need to check automatically added bower files to identify the root cause of the error. Those automatically added files may be hidden in the solution explorer.




How to fix the error
  • If you use visual studio read error output carefully and it mentioned the bower file need to correct.


  •  Open relevant bower file




  • Remove unwanted content from it (all other content which located after main curly braces) and save it then it will fix the Dependency error instantly.