Code: Kendo Combobox with Angular in MVC
As you see the below snippet, the element is same as Select with the different pre-defined attributes for kendo and Angular.
kendo-combo-box – Defines the kendo combobox to be displayed on the UI.
k-data-text-field – Defines the text value for the combo box data.
k-data-value-field – Defines the value field for the combo box data.
k-filter – As we know in combo box, we can take user input for few letters and then the data source gets filtered.
ng-disabled – Angular attribute to disable the combo box on first load.
k-auto-bind – Defines the property auto bind for the data source of combo box.
k-min-length – Defines the minimum characters to be input to auto complete the filter.
k-ng-model – Here instead of normal Angular attribute, ng-model, k-ng-model is used in order to set the kendo combo box model property. This by default takes the k-data-value-field.
k-on-change – This function is triggered when the change event is fired. Instead of ng-change which by default will require ng-model attribute, we use k-on-change.
Hope this simple snippet comes in handy for developers using kendo and Angular. Similar can be used for Kendo Drop down list as well.
1 2 3 4 5 6 7 8 9 10 11 12 |
<select kendo-combo-box id="AnyID" k-data-text-field="'Key'" k-data-value-field="'Value'" k-filter="'contains'" ng-disabled="true" k-auto-bind="true" k-min-length="3" k-ng-model="model.ComboProperty" k-on-change="FunctionName()" style="width:73%;"> </select> |
Code:Customizing scrolling on an HTML Page
This simple code snippet helps you customize the scrolling event on your HTML web page. It tracks each scroll.
This would be very handy when designing a single page application.
Now-a-days when user scrolls on the Single page application, the navigation link changes class and displays the user.
Use the snippet and let me know:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function onScroll() { var scrollPos = $(document).scrollTop(); $('.navbar .navClick').each(function () { var currLink = $(this); var refElement = $(currLink.attr("href")); if (refElement.position() != undefined && refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) { $('.navbar .navClick').removeClass("active"); currLink.addClass("active"); } else { currLink.removeClass("active"); } }); } $(document).on('click', '.navClick', function (event) { event.preventDefault(); var target = "#" + this.getAttribute('data-target'); $('a').each(function () { $(this).removeClass('active'); }); $(this).addClass('active'); $('html, body').animate({ scrollTop: $(target).offset().top + 70 }, "slow", "linear", function () { $(document).on("scroll", onScroll); }); }); |
The second snippet helps you detect the ID clicked and then help you toggle the active class for the nav link clicked. We need to add data-target on the HTML element in order to track the click and animate the User to the selected div on click.
Hope this helps.
Code:Select Insert using Stored Procedure
This snippet is a query which does select Insert operation into a table. We here would see that creating a Stored procedure which actually selects the data from a table and may be insert into the same table or other tables with identical columns. here I would show you how to insert into the same table.
This is really handy when there is a huge amount of records to be selected and inserted and using foreach in Entity Framework would hamper the performance heavily.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
ALTER PROCEDURE [dbo].[spAddRecordsForNewX] -- Add the parameters for the stored procedure here @fkID INT, @conditionID INT, AS BEGIN --================== SELECT INSERT QUERY FOR THE RESPECTIVE TABLE RECORDS=================-- BEGIN TRANSACTION INSERT INTO dbo.[TABLE#] SELECT @fkID, pRel.Column1, pRel.Column2, pRel.Column3, pRel.Column4, pRel.Column5, FROM dbo.[TABLE#] as pRel WHERE PRIMARYKEY = @conditionID --This would be a primary key condition to retrive and Insert the codes IF @Rollback = 1 ROLLBACK TRANSACTION ELSE COMMIT //The transaction is tracked and rolled back if any issue |
Code:PDF generation using Rotativa with response
This code snippet using the Controller Context Response to view the PDF file in another window without downloading it or showing in the same window. Below is the snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public ActionResult ReportTest() { var pdfResult = new PartialViewAsPdf("_pdfTemplate") //This is HTML that would be generated as PDF { FileName = Constants.PDF_REPORT_NAME + DateTime.Now.ToShortDateString() + Constants.PDF_EXT, //Change the name and constants confirm form client CustomSwitches = "ADD SWITCHES HERE FOR HEADER FOOTER" }; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); //Send the file to the output stream var resultSet = pdfResult.BuildPdf(ControllerContext); Response.Buffer = true; //Set the output stream to the correct content type (PDF). Response.ContentType = "application/pdf"; Response.AddHeader("Accept-Ranges", "bytes"); //Output the file Response.BinaryWrite(resultSet); //Flushing the Response to display the serialized data Response.End(); Response.Flush(); //to the client browser. return null; } |
Simple Loop Program
A very simple looping program for beginners as well as for QAs who are into script writing for Automation. I have created in dot net fiddle. Please find the link as well. This is a simple program which loops through from 1 to 100 and dispays out put as:
Processing 1 …
1 is a prime Number
1 is an odd number
Processing 2 …
2 is a prime Number
2 is an even number
Processing 3 …
3 is a prime Number
3 is an odd number …
And so on.
So the code goes as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using System; public class Program { public static void Main() { for(int i=1;i<=100;i++){ Console.WriteLine("Processing {0} ...",i); //Check for Prime Number var primeCheckFlag = true; for(int primeCheker = 2; primeCheker<= i/2;++primeCheker){ if(i%primeCheker==0){ primeCheckFlag = false; break; } } if(primeCheckFlag==true){ Console.WriteLine("{0} is a prime Number", i); } else{ Console.WriteLine("{0} is not a prime Number", i); } //Check for number has zeroes var zeroCheck = i/5; if(i%5 == 0 && zeroCheck % 2 ==0) { Console.WriteLine("{0} has zero in it", i); } //Check for Even/Odd if(i % 2 == 0){ Console.WriteLine("{0} is an even number \n", i ); } else{ Console.WriteLine("{0} is an odd number \n", i); } } } } |