Git Product home page Git Product logo

datatable's Introduction

DataTable API License

DataTable is a library for create material data table simply. In this version it is only possible to create tables with string values. Soon, image fields, checkbox fields, input fields and etc will be possible.

This library is optimized for both ltr and rtl languages

This library is also available at JitPack.io

this library is compatible to androidx

Preview

screenshot 1 screenshot 2 screenshot 3 screenshot 4

Setup

The simplest way to use this library is to add the library as dependency to your build.

Gradle

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

// builde.gradle(app level)
dependencies {
    implementation 'com.github.salehyarahmadi:DataTable:v1.0.0'
}

Usage

XML

<ir.androidexception.datatable.DataTable
        android:id="@+id/data_table"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        app:header_gravity="center"
        app:row_gravity="center"
        app:header_vertical_padding="16dp"
        app:header_horizontal_padding="0dp"
        app:row_vertical_padding="16dp"
        app:header_text_size="12sp"
        app:row_text_size="12sp"
        app:row_text_color="#000"
        app:header_text_color="#000"
        app:row_background_color="#fff"
        app:header_background_color="#fff"
        app:persian_number="false"
        app:corner_radius="8dp"
        app:direction="ltr"
        app:shadow="8dp"/>

Java

DataTable dataTable = findViewById(R.id.data_table);
        
DataTableHeader header = new DataTableHeader.Builder()
    .item("field name", field weight)
    .item("field name", field weight)
    .item("field name", field weight)
    .item("field name", field weight)
    ...
    .build();
    
ArrayList<DataTableRow> rows = new ArrayList<>();
    // define 200 fake rows for table 
    for(int i=0;i<200;i++) {
        Random r = new Random();
        int random = r.nextInt(i+1);
        int randomDiscount = r.nextInt(20);
        DataTableRow row = new DataTableRow.Builder()
            .value("Product #" + i)
            .value(String.valueOf(random))
            .value(String.valueOf(random*1000).concat("$"))
            .value(String.valueOf(randomDiscount).concat("%"))
            ...
            .build();
        rows.add(row);
    }

dataTable.setTypeface(typeface);
dataTable.setHeader(header);
dataTable.setRows(rows);
dataTable.inflate(context);

field weight is in integer value for determine field width. This value is relative and field size depends on the weight of the other fields. For example, if a field weight be 2 and other field weight be 4, This means that the width of the second field is twice that of the width of first field. Also, you can define unlimited number of fields.

You can set xml attributes programmatically

dataTable.setHeaderTextSize();
dataTable.setRowTextSize();
dataTable.setHeaderTextColor();
dataTable.setRowTextColor();
dataTable.setHeaderBackgroundColor();
dataTable.setRowBackgroundColor();
dataTable.setHeaderVerticalPadding();
dataTable.setHeaderHorizontalPadding();
dataTable.setHeaderVerticalMargin();
dataTable.setHeaderHorizontalMargin();
dataTable.setRowVerticalPadding();
dataTable.setRowHorizontalPadding();
dataTable.setRowVerticalMargin();
dataTable.setRowHorizontalMargin();
dataTable.setHeaderGravity();
dataTable.setRowGravity();
dataTable.setDividerThickness();
dataTable.setDividerColor();
dataTable.setCornerRadius();
dataTable.setShadow();
dataTable.setDirection();
dataTable.setPersianNumber();

License

Copyright 2019 DataTable

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
       

datatable's People

Contributors

salehyarahmadi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.