0

Datatable Search On Enter

Finally !!!!

Reference: jquery - datatables global search on keypress of enter key instead of any key keypress - Stack Overflow

Need to declare function on initComplete event. And use search function.

Datatable version 1.11.

$(function() {
    var  table = $('#DataTable1').DataTable({
            proccessing: true,
            searching: true,
            paging: true,
            serverSide: true,
            initComplete: function() {
                $('.dataTables_filter input').unbind();
                $('.dataTables_filter input').bind('keyup', function(e){
                    var code = e.keyCode || e.which;
                    if (code == 13) {
                        table.search(this.value).draw();
                    }
                });
            },
            ajax: {
            url: '@Url.Action("Paginacao")',
            type: 'POST'
        },
        language: {
            url: '/plugins/datatables/lang/Portuguese-Brasil.json'
        },
        columns:
        [
                { "data": "id", visible: false },
                { "data": "nome", "autoWidth": true },
                { "data": "cnpj", "autoWidth": true },
            {
                "render": function(data, type, full, meta) {
                    return '<a href=@Url.Action("Editar", "Usuario")?id='+full.id+'><b><i class=\"fa fa-edit bigfonts\"></i> Editar</b></a>';
                }
            }
        ]
    });

});
0

PHP - Access Object Attributes Dynamically

I want to access object attributes with child objects dynamically just by specifying the attribute in a string variable. 

$book->category->name


$attr="category->name";
$book=\App\Models\Book::find(2);
echo $book->$attr;

Result : null

Solution :

$attr="category->name";
$book=\App\Models\Book::find(2);
$parts=explode("->",$attr);
$h=$book;
foreach($parts as $p){
    $h=$h->$p;
}
echo $h;

Result : book category name



0

Using Docker Git Client

I've got a situation where the git client is not allowed to be installed on the production server (due to strict user policies) but I still want to use git without having to install the git client.

Finally, I found a solution using docker. (For this test I used Docker Desktop on Windows 11).

To clone a repository, just use the instructions below.


  docker run -ti  -v e:\repo\project1:/git alpine/git clone https://gitlab.com/test/project1.git ./

Need to map the volume (on my windows folder) to /git (in docker) and clone the repository to the current folder (./).

Then, git started cloning the repository.

To pull changes :


  docker run -ti --rm -v e:\repo\project1:/git alpine/git pull

0

ASP.NET Slug (MVC)

I want to use slug in ASP.NET MVC application. The URL should be something like this

localhost:58128/ABMB 

Here are the steps required to do so:

1. Defined the route (startup.cs)


 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

 routes.MapRoute(
   "Slug",
   "{slug}", 
       new { controller = "Home", action = "ScholarInfoDetails" } 
 );

2. Create SlugToIdAttribute.cs class

using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

/// 
/// Summary description for SlugToIdAttribute
/// 
public class SlugToIdAttribute : ActionFilterAttribute
{
    private ApplicationDbContext db = new ApplicationDbContext();

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var slug = filterContext.RouteData.Values["slug"] as string;
        if (slug != null)
        {
            var model=db.Banks.Where(x => x.Code == slug).First();
            if (model != null) {
                filterContext.ActionParameters["id"] = model.id.ToString();
            }            
        }
        base.OnActionExecuting(filterContext);
    }
}

3. Use in the controller. Add annotation [SlugToId]  

[AllowAnonymous]
[SlugToId]
public ActionResult ScholarInfoDetails(String id)
{
	var r = new ContentResult();
	r.Content = "Hello World " + id.ToString();
	return r;
}


Now the function can be access using slug. E.g http://localhost:58128/ABMB. Result will be something like this :
Hello World 2
 
Copyright © peyotest