1.0.0 • Published 5 years ago

row-selected-library v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

Row Selected Library

If you are displaying a table with an id column and you have controls to handle your registers. But, you don't know how to get the id. Well, you're in the correct library.

IdBook NameAuthorCategory
1Eloquent JavaScriptMarijn HaverbekeProgramming
2Smashing Node.jsGuillermo RauchProgramming
3The Road to learn ReactRobin WieruchProgramming
4Clean CodeRobert C. MartinProgramming

Installation

Row Selected Library requires Node.js to run.

Install the package with npm.

$ npm install row-selected-library --save -dev

Usage

First you've to import and create a new instance of Row Selected Library class.

import RowSelectedLibrary from 'row-selected-library';

Then, you'll need to pass the necessary parameters. The first three parameters are the ids of the html controls to handle the registers. The fourth is the id of the body table and the last one is the css class to identify a selected row.

  • Id of the control to see the register.
  • Id of the control to edit the register.
  • Id of the control to delete the register.
  • Id of the body table.
  • Css class to distinguish the selected row.
const libraryInstance = new RowSelectedLibrary(
    'idSeeControl','idEditControl','idDeleteControl',
	'bodyTable','cssClass');

Now, initialize the library.

libraryInstance.activateRowSelection();

Finally, you can get the id of the selected row.

const getRowSelected = () => {
  const rowSelected = libraryInstance.getRowSelected();
  if(rowSelected === false) {
      alert('Please, select a row from the table.')
  } else {
      console.log(rowSelected) // Id of the selected row. Now you can do whatever you want.
  }
}

Notes

  • The id column needs to be at the first column of the table.
  • It's not necessary to display the id column. It works perfectly without displaying the id column.
1.0.0

5 years ago