• FRAMEWORK

DataTables with JS

A lightweight table component built on jQuery and compatible with DataTables 1.10. Features include: column visibility (ColVis), per-column filtering, inline edit mode, optional export (Excel/PDF), standard but toggleable sticky header, row selection with select-all, row status highlighting, language detection via HTML attributes with extendable/customizable i18n support, optional responsive mode, customizable pager, multi-table support, and configurable CORS options for flexible data sources. Additionally, it can be easily integrated with backend services such as .NET Core.


    $(function () {
       FoDataTables.create({
           url: 'https://fof.ford.com.tr/Content/json/products.json',
           tableSelector: '#products',
           pageLength: 10,
           cors: true
       });
   });   

.NET Core ile Veri Sağlama

FoDataTables hem client-side JSON hem de server-side DataTables uyumlu formatı destekler. Server-side senaryoda DataTables start, length, search[value] ve order[0][column] gibi parametreleri gönderir. Backend tarafında bu parametreleri okuyarak filtreleme, sıralama ve sayfalama işlemleri yapılmalı; dönüş JSON formatında mutlaka şu alanlar olmalıdır:

  • data → Tabloya gönderilecek satırların listesi (array)
  • recordsTotal → Veritabanındaki toplam satır sayısı
  • recordsFiltered → Filtre sonrası satır sayısı
Kısa Örnek (Client-Side için basit JSON)
app.MapGet("/api/products", () =>
{
    // Örn: ilk 100 ürünü dön
    return Results.Json(list.Take(100));
});
Server-Side Örnek (Paging, Arama, Sıralama dahil)
app.MapGet("/api/products", (HttpRequest req) =>
{
    // DataTables parametrelerini oku
    int start = int.TryParse(req.Query["start"], out var s) ? s : 0;
    int length = int.TryParse(req.Query["length"], out var l) ? l : 10;
    string search = req.Query["search[value]"];
    string orderCol = req.Query["order[0][column]"];
    string orderDir = req.Query["order[0][dir]"];

    IQueryable query = list.AsQueryable();

    // Arama
    if (!string.IsNullOrWhiteSpace(search))
        query = query.Where(p => p.Title.Contains(search, StringComparison.OrdinalIgnoreCase));

    // Sıralama (örnek: Title’a göre)
    if (orderCol == "1" && orderDir == "asc")
        query = query.OrderBy(p => p.Title);
    else if (orderCol == "1" && orderDir == "desc")
        query = query.OrderByDescending(p => p.Title);

    int total = list.Count;
    int filtered = query.Count();

    var page = query.Skip(start).Take(length).ToList();

    return Results.Json(new {
        data = page,
        recordsTotal = total,
        recordsFiltered = filtered
    });
});
Product POCO Class
  • Alan adları, DataTables’ın beklediği JSON kolonlarıyla eşleşmelidir (title, type, author …).
  • ASP.NET Core varsayılan System.Text.Json camelCase kullanır. Birebir ad eşlemesi için [JsonPropertyName("title")] kullanabilirsiniz.
  • Backend’den dönen List<Product>, otomatik olarak DataTables satırlarına map edilir.
public class Product
{
    public string Title  { get; set; }
    public string Type   { get; set; }
    public string Author { get; set; }
    public int    Year   { get; set; }
    public int    Qty    { get; set; }
    public decimal Price { get; set; }
    public string Path   { get; set; }
}
Notlar
  • Büyük datasetlerde mutlaka server-side mod kullanılmalı.
  • DataTables uyumu için JSON alanları: data, recordsTotal, recordsFiltered.
  • ata yönetimi için try/catch + Results.Problem() kullanabilirsiniz.
  • Product sınıfını tablo kolonlarıyla uyumlu modelleyin.

.NET Core Data Provider

FoDataTables supports both client-side JSON and server-side DataTables-compatible format. In server-side mode DataTables posts start, length, search[value], and order[0][column] parameters. Your backend should handle filtering, sorting, and paging; the JSON response must include:

  • data → Array of rows to display
  • recordsTotal → Total rows in DB
  • recordsFiltered → Row count after filtering
Short Example (simple client-side JSON)
app.MapGet("/api/products", () =>
{
    // Return first 100 rows
    return Results.Json(list.Take(100));
});
Server-Side Example (Paging, Search, Order)
app.MapGet("/api/products", (HttpRequest req) =>
{
    int start  = int.TryParse(req.Query["start"], out var s) ? s : 0;
    int length = int.TryParse(req.Query["length"], out var l) ? l : 10;
    string search   = req.Query["search[value]"];
    string orderCol = req.Query["order[0][column]"];
    string orderDir = req.Query["order[0][dir]"];

    IQueryable query = list.AsQueryable();

    if (!string.IsNullOrWhiteSpace(search))
        query = query.Where(p => p.Title.Contains(search, StringComparison.OrdinalIgnoreCase));

    if (orderCol == "1" && orderDir == "asc")
        query = query.OrderBy(p => p.Title);
    else if (orderCol == "1" && orderDir == "desc")
        query = query.OrderByDescending(p => p.Title);

    int total    = list.Count;
    int filtered = query.Count();

    var page = query.Skip(start).Take(length).ToList();

    return Results.Json(new {
        data = page,
        recordsTotal = total,
        recordsFiltered = filtered
    });
});
Product POCO Class
  • Property names should match DataTables JSON columns (title, type, author …).
  • ASP.NET Core’s System.Text.Json uses camelCase by default; use [JsonPropertyName("title")] if you need exact names.
  • Returning List<Product> maps directly to table rows.
public class Product
{
    public string Title  { get; set; }
    public string Type   { get; set; }
    public string Author { get; set; }
    public int    Year   { get; set; }
    public int    Qty    { get; set; }
    public decimal Price { get; set; }
    public string Path   { get; set; }
}
Notes
  • For large datasets use server-side mode.
  • Required JSON fields: data, recordsTotal, recordsFiltered.
  • Add try/catch and return Results.Problem() on errors.
  • Model Product to match your table columns.

Furnizare date cu .NET Core

FoDataTables suportă atât JSON client-side, cât și format compatibil DataTables pe server-side. În modul server-side, DataTables trimite parametri precum start, length, search[value] și order[0][column]. Backend-ul trebuie să aplice filtrare, sortare și paginare; răspunsul JSON trebuie să conțină:

  • data → Lista de rânduri afișate
  • recordsTotal → Totalul rândurilor în DB
  • recordsFiltered → Rânduri după filtrare
Exemplu scurt (JSON simplu pentru client-side)
app.MapGet("/api/products", () =>
{
    // Primele 100 de înregistrări
    return Results.Json(list.Take(100));
});
Exemplu Server-Side (Paging, Căutare, Sortare)
app.MapGet("/api/products", (HttpRequest req) =>
{
    int start  = int.TryParse(req.Query["start"], out var s) ? s : 0;
    int length = int.TryParse(req.Query["length"], out var l) ? l : 10;
    string search   = req.Query["search[value]"];
    string orderCol = req.Query["order[0][column]"];
    string orderDir = req.Query["order[0][dir]"];

    IQueryable query = list.AsQueryable();

    if (!string.IsNullOrWhiteSpace(search))
        query = query.Where(p => p.Title.Contains(search, StringComparison.OrdinalIgnoreCase));

    if (orderCol == "1" && orderDir == "asc")
        query = query.OrderBy(p => p.Title);
    else if (orderCol == "1" && orderDir == "desc")
        query = query.OrderByDescending(p => p.Title);

    int total    = list.Count;
    int filtered = query.Count();

    var page = query.Skip(start).Take(length).ToList();

    return Results.Json(new {
        data = page,
        recordsTotal = total,
        recordsFiltered = filtered
    });
});
Clasa POCO Product
  • Numele proprietăților ar trebui să corespundă coloanelor JSON ale tabelului (title, type, author …).
  • System.Text.Json folosește camelCase implicit; pentru mapare exactă utilizați [JsonPropertyName("title")].
  • Returnarea unui List<Product> se mapează direct pe rândurile tabelului.
public class Product
{
    public string Title  { get; set; }
    public string Type   { get; set; }
    public string Author { get; set; }
    public int    Year   { get; set; }
    public int    Qty    { get; set; }
    public decimal Price { get; set; }
    public string Path   { get; set; }
}
Note
  • Pentru seturi mari de date folosiți modul server-side.
  • Câmpuri JSON necesare: data, recordsTotal, recordsFiltered.
  • Gestionați erorile cu try/catch și returnați Results.Problem().
  • Modelați Product conform coloanelor din tabel.

Dokümantasyon

DataTables 1.10 uyumlu, jQuery ile geliştirilmiş tablo bileşenidir. Özellikleri; ColVis ile kolon seçimi, kolon bazlı filtreleme, inline edit modu ile düzenleme, isteğe bağlı export (Excel/PDF), standart ama kapatılabilir sticky header, satır bazlı seçim ve tümünü seç fonksiyonları, satır durum renklendirmeleri, HTML attributeleri ile dil algılama ve istenirse değiştirilebilir/eklenebilir dil seçenekleri (i18n), opsiyonel responsive mod, değiştirilebilir pager, birden fazla tablo desteği, ve isteğe göre düzenlenebilir CORS seçenekleri ile modüler bir yapıdadır. Ayrıca .NET Core gibi backend servislerle kolayca entegre edilebilir.

create(options) — Seçenekler

OptionTipVarsayılanAçıklama
urlstringJSON kaynağı
dataArrayURL yerine doğrudan veri
tableSelectorstring#productsTablo seçicisi
pageLengthnumber10Satır sayısı
header"sticky"/"none"stickyHeader davranışı
corsboolfalseCORS fetch modu
fetchOptionsobjectCustom fetch ayarları
rowIdstring|fnSatır id eşleme
statusFnfn(row)varsayılanDurum sınıfı belirler
languagestring<html lang>Dil (tr/en/ro)
editbooltrueDüzenleme modu aktif/deaktif
editTogglebooltrueDüzenleme modu butonu aktif/deaktif
actionsbooltrueİşlemler kolonu aktif/deaktif
rowSelectbooltrueSatır seçimi aktif/deaktif
colVisbooltrueKolon seçimi aktif/deaktif

Veri Kaynağı / Fetch Opsiyonları

// Aynı domain
FoDataTables.create({ url:"/api/products", tableSelector:"#products" });

// Farklı domain (CORS)
FoDataTables.create({ url:"https://fof.ford.com.tr/Content/json/products.json", tableSelector:"#products", cors:true });

// Data doğrudan
FoDataTables.create({ data:[{title:"The Hobbit"}], tableSelector:"#products" });

HTML’den Kolon Tanımı

<th data-key="price" class="fo-datatables-col-small fo-text-right">Fiyat</th>

Seçim & ID’ler

const dt = $('#products').DataTable();
const selected = dt.rows('.row-selected').data().toArray();

Inline Edit

<th data-key="year" data-type="number">Yıl</th>

Kolon Görünürlüğü (ColVis)

buttons: [ { extend:'colvis', text:'Kolonlar' } ]

Sticky Header

FoDataTables.create({ header:"sticky", stickyMeasure:false });

Genişlik & Scroll

<th class="fo-datatables-col-small">...</th>
<th class="fo-datatables-col-full">...</th>

Dil (i18n)

FoDataTables.create({ language:"tr" });
FoDataTables.extendLang('de',{dt:{...}});

.NET Core ile Veri Sağlama

app.MapGet("/api/products", () => Results.Json(list.Take(100)));

Aynı Sayfada Birden Fazla Tablo

Footer elementleri class ile scope edilir: .fo-datatables-info, .fo-datatables-pager.

Satır Durum Renkleri (Default, Success, Info, Warning ve Error)

FoDataTables.create({
  statusFn: (r) => r.qty===0 ? "status-error" : "status-default"
});

Metotlar / Fonksiyonlar

MetotAçıklamaÖrnek
FoDataTables.create(opts)Yeni tablo başlatırFoDataTables.create({url:"..."})
FoDataTables.extendLang(code,obj)Yeni dil ekler/override ederFoDataTables.extendLang("de",{dt:{...}})

Inline Edit – Date Kullanımı

Bir kolonda date tipi kullanılacaksa, ilgili <th> elementine data-type="date" attribute’u eklenmelidir. Bu durumda hücreye tıklandığında tarayıcının kendi HTML5 datepicker’ı açılır. Değerler ISO formatında (YYYY-MM-DD) tutulur.

<thead>
  <tr>
    <th data-key="title">Başlık</th>
    <th data-key="author">Yazar</th>
    <th data-key="published" data-type="date">Yayın Tarihi</th>
  </tr>
</thead>

Not: JSON’daki tarih alanları "2025-08-28" gibi ISO 8601 formatında olmalıdır. Backend tarafında C# için DateTime? property’si önerilir.

Sık Sorulan Sorular

İlk yüklemede 100 satır göstermek istiyorum, nasıl yaparım?
pageLength: 100 parametresini create içinde geçebilirsiniz.

Seçilen satırların id’lerini veya verilerini nasıl alabilirim?
dt.rows('.row-selected').data() ile seçili satırların datalarını alabilirsiniz.

Tabloda çok fazla kolon olduğunda yatay scroll otomatik gelir mi?
Evet, .nowrap sınıfını tabloya ekleyip tabloyu bir .fo-datatables-js-wrap içine aldığınızda yatay scroll çıkar.

Sticky header’ı kapatabilir miyim?
Evet, header: "none" parametresini create içinde belirterek sticky header’ı devre dışı bırakabilirsiniz.

Dil ayarını nasıl değiştirebilirim?
Varsayılan olarak <html lang="tr"> okunur. İstediğiniz dili zorlamak için language: "en" veya language: "ro" parametresi geçebilirsiniz.

Bir kolonu gizlemek istiyorum, nasıl yaparım?
Kolonu tanımlarken visible:false opsiyonunu ekleyebilirsiniz ya da ColVis menüsünden kullanıcıya kolon gizleme seçeneği sunabilirsiniz.

Backend’den gelen veri çok büyük, performanslı nasıl çalıştırabilirim?
serverSide:true ile DataTables server-side moduna alınmalı ve backend’in DataTables formatında (data, recordsTotal, recordsFiltered) JSON döndürmesi gerekir.

Documentation

A jQuery-based table component compatible with DataTables 1.10. Features include: column selection with ColVis, per-column filtering, inline edit mode, optional export (Excel/PDF), standard but toggleable sticky header, row selection and select-all, row status highlighting, automatic language detection via HTML attributes with extendable/customizable i18n, optional responsive mode, customizable pager, multiple table support, and configurable CORS options for modular integration. It can also be easily integrated with backend services such as .NET Core.

create(options) — Options

OptionTypeDefaultDescription
urlstringJSON source
dataArrayInline data instead of fetch
tableSelectorstring#productsTable selector
pageLengthnumber10Rows per page
header"sticky"/"none"stickyHeader behavior
corsboolfalseEnable fetch {mode:'cors'}
fetchOptionsobjectCustom fetch settings
rowIdstring|fnRow id mapping
statusFnfn(row)defaultRow status class function
languagestring<html lang>Language (tr/en/ro)
editbooltrueEdit mode on/off
editTogglebooltrueEdit mode button on/off
actionsbooltrueProcess column on/off
rowSelectbooltrueRow Select on/off
colVisbooltrueColumn Select on/off

Data Source / Fetch Options

// Same domain
FoDataTables.create({ url:"/api/products", tableSelector:"#products" });

// Cross-domain (CORS)
FoDataTables.create({ url:"https://fof.ford.com.tr/Content/json/products.json", tableSelector:"#products", cors:true });

// Inline data
FoDataTables.create({ data:[{title:"The Hobbit"}], tableSelector:"#products" });

Define Columns from HTML

<th data-key="price" class="fo-datatables-col-small fo-text-right">Price</th>

Selection & IDs

const dt = $('#products').DataTable();
const selected = dt.rows('.row-selected').data().toArray();

Inline Edit

<th data-key="year" data-type="number">Year</th>

Column Visibility (ColVis)

buttons: [ { extend:'colvis', text:'Columns' } ]

Sticky Header

FoDataTables.create({ header:"sticky", stickyMeasure:false });

Width Presets & Scroll

<th class="fo-datatables-col-small">...</th>
<th class="fo-datatables-col-full">...</th>

Internationalization (i18n)

FoDataTables.create({ language:"en" });
FoDataTables.extendLang('de',{dt:{...}});

.NET Core Integration

app.MapGet("/api/products", () => Results.Json(list.Take(100)));

Multiple Tables on Same Page

Footer elements are scoped by class: .fo-datatables-info, .fo-datatables-pager.

Row Status Colors (Default, Success, Info, Warning, Error)

FoDataTables.create({
  statusFn: (r) => r.qty===0 ? "status-error" : "status-default"
});

Methods / Functions

MethodDescriptionExample
FoDataTables.create(opts)Initialize new tableFoDataTables.create({url:"..."})
FoDataTables.extendLang(code,obj)Add/override languageFoDataTables.extendLang("de",{dt:{...}})

FAQ — Frequently Asked Questions

How can I show 100 rows by default?
Set pageLength: 100 in the create options.

How do I get IDs or data of selected rows?
Use dt.rows('.row-selected').data() to retrieve selected row data.

Does horizontal scroll appear automatically with many columns?
Yes, adding .nowrap to the table and wrapping with .fo-datatables-js-wrap will enable horizontal scroll.

Can I disable sticky header?
Yes, set header: "none" in the create options.

How do I change the language?
By default it reads <html lang>. Override with language:"en" or language:"ro".

How can I hide a column?
Add visible:false to the column config, or use the ColVis menu.

What if my dataset is huge?
Enable serverSide:true and return JSON in DataTables format (data, recordsTotal, recordsFiltered).

Documentare

Un component de tabel bazat pe jQuery, compatibil cu DataTables 1.10. Caracteristici: selectare coloane cu ColVis, filtrare pe coloană, mod de editare inline, export opțional (Excel/PDF), antet sticky standard dar dezactivabil, selectare rânduri și „selectează tot”, evidențierea stării rândurilor, detectarea limbii prin atribute HTML cu suport i18n extensibil/personalizabil, mod responsive opțional, pager configurabil, suport pentru mai multe tabele, și opțiuni CORS configurabile pentru o integrare modulară. De asemenea, poate fi integrat ușor cu servicii backend precum .NET Core.

create(options) — Opțiuni

OpțiuneTipImplicitDescriere
urlstringSursă JSON
dataArrayDate inline
tableSelectorstring#productsSelectoare tabel
pageLengthnumber10Rânduri per pagină
header"sticky"/"none"stickyComportament antet
corsboolfalseActivează fetch {mode:'cors'}
fetchOptionsobjectSetări fetch custom
rowIdstring|fnMapare id rând
statusFnfn(row)implicitClasă status rând
languagestring<html lang>Limbă (tr/en/ro)

Sursă de date / Opțiuni Fetch

// Același domeniu
FoDataTables.create({ url:"/api/products", tableSelector:"#products" });

// Domeniu diferit (CORS)
FoDataTables.create({ url:"https://fof.ford.com.tr/Content/json/products.json", tableSelector:"#products", cors:true });

// Date inline
FoDataTables.create({ data:[{title:"The Hobbit"}], tableSelector:"#products" });

Coloane definite din HTML

<th data-key="price" class="fo-datatables-col-small fo-text-right">Preț</th>

Selecție & ID-uri

const dt = $('#products').DataTable();
const selected = dt.rows('.row-selected').data().toArray();

Editare Inline

<th data-key="year" data-type="number">An</th>

Vizibilitate Coloane (ColVis)

buttons: [ { extend:'colvis', text:'Coloane' } ]

Antet Sticky

FoDataTables.create({ header:"sticky", stickyMeasure:false });

Lățime & Scroll

<th class="fo-datatables-col-small">...</th>
<th class="fo-datatables-col-full">...</th>

i18n — Internaționalizare

FoDataTables.create({ language:"ro" });
FoDataTables.extendLang('de',{dt:{...}});

Integrare .NET Core

app.MapGet("/api/products", () => Results.Json(list.Take(100)));

Mai multe tabele pe aceeași pagină

Elementele footer se delimitează prin clase: .fo-datatables-info, .fo-datatables-pager.

Culori Status Rânduri (Default, Success, Info, Warning, Error)

FoDataTables.create({
  statusFn: (r) => r.qty===0 ? "status-error" : "status-default"
});

Metode / Funcții

MetodăDescriereExemplu
FoDataTables.create(opts)Inițializează tabel nouFoDataTables.create({url:"..."})
FoDataTables.extendLang(code,obj)Adaugă/înlocuiește o limbăFoDataTables.extendLang("de",{dt:{...}})

Întrebări frecvente

Cum afișez 100 de rânduri la încărcare?
Setează pageLength: 100 în opțiuni.

Cum obțin ID-urile sau datele rândurilor selectate?
Folosește dt.rows('.row-selected').data().

Scroll orizontal apare automat cu multe coloane?
Da, adaugă .nowrap pe tabel și folosește .fo-datatables-js-wrap.

Pot dezactiva sticky header?
Da, setează header: "none" în opțiuni.

Cum schimb limba?
Implicit citește <html lang>. Suprascrie cu language:"en" sau language:"ro".

Cum ascund o coloană?
Adaugă visible:false sau folosește meniul ColVis.

Datele sunt foarte mari, cum optimizez?
Activează serverSide:true și returnează JSON în format DataTables (data, recordsTotal, recordsFiltered).

DataTable with JavaScript

FO Datatables for ASP.NET MVC is a powerful component, which allows you to visualize and edit data via its table representation. It provides a variety of options about how to present and perform operations over the underlying data, such as paging, sorting, filtering, exporting and many more.

You can also use this tool with jQuery

Name Position Office Age Start date Salary
Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000
Cedric Kelly Senior Javascript Developer Edinburgh 22 2012/03/29 $433,060
Airi Satou Accountant Tokyo 33 2008/11/28 $162,700
Brielle Williamson Integration Specialist New York 61 2012/12/02 $372,000
Herrod Chandler Sales Assistant San Francisco 59 2012/08/06 $137,500
Rhona Davidson Integration Specialist Tokyo 55 2010/10/14 $327,900
Colleen Hurst Javascript Developer San Francisco 39 2009/09/15 $205,500
Sonya Frost Software Engineer Edinburgh 23 2008/12/13 $103,600
Jena Gaines Office Manager London 30 2008/12/19 $90,560
Quinn Flynn Support Lead Edinburgh 22 2013/03/03 $342,000
Charde Marshall Regional Director San Francisco 36 2008/10/16 $470,600
Haley Kennedy Senior Marketing Designer London 43 2012/12/18 $313,500
Tatyana Fitzpatrick Regional Director London 19 2010/03/17 $385,750
Michael Silva Marketing Designer London 66 2012/11/27 $198,500
Paul Byrd Chief Financial Officer (CFO) New York 64 2010/06/09 $725,000
Gloria Little Systems Administrator New York 59 2009/04/10 $237,500
Bradley Greer Software Engineer London 41 2012/10/13 $132,000
Dai Rios Personnel Lead Edinburgh 35 2012/09/26 $217,500
Jenette Caldwell Development Lead New York 30 2011/09/03 $345,000
Brenden Wagner Software Engineer San Francisco 28 2011/06/07 $206,850
Fiona Green Chief Operating Officer (COO) San Francisco 48 2010/03/11 $850,000
Shou Itou Regional Marketing Tokyo 20 2011/08/14 $163,000
Michelle House Integration Specialist Sydney 37 2011/06/02 $95,400
Suki Burks Developer London 53 2009/10/22 $114,500
Vivian Harrell Financial Controller San Francisco 62 2009/02/14 $452,500
Timothy Mooney Office Manager London 37 2008/12/11 $136,200
Jackson Bradshaw Director New York 65 2008/09/26 $645,750
Olivia Liang Support Engineer Singapore 64 2011/02/03 $234,500
Bruno Nash Software Engineer London 38 2011/05/03 $163,500
Donna Snider Customer Support New York 27 2011/01/25 $112,000