इस पेज का अनुवाद मशीन द्वारा किया गया है और इसमें त्रुटियाँ हो सकती हैं। मूल अंग्रेज़ी पढ़ें

एलिमेंट

Table

Table कुछ पंक्तियों को व्यवस्थित करता है जिन्हें ऐप चिल्ड्रन के रूप में लिखता है (इनवॉइस, सारांश, तुलना), और स्क्रीन रीडर को एक तालिका देता है: तालिका स्वयं, पंक्तियों के समूह, पंक्तियाँ, कॉलम हेडर और सेल, प्रत्येक अपनी भूमिका (role) के साथ। इसके भाग हैं TableHeader, TableBody और TableFooter (पंक्तियों के समूह), TableRow (इसके सेल साथ-साथ), TableHead (किसी कॉलम का हेडर सेल), TableCell और TableCaption। रूप-रंग ऐप का होता है: किसी भी भाग के अपने रंग, बॉर्डर, पैडिंग या चौड़ाई नहीं होते, और प्रत्येक भाग ऐप के class और style लेता है। बहुत सारी पंक्तियों, सॉर्टिंग, चयन और आकार बदले जा सकने वाले कॉलम के लिए, DataTable ही तालिका है।

el-table.tsx
el-table.tsxLive
import { mount, Text, View } from "nsh";
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "nsh/base";
import { size, Stage, ui } from "./palette";

// A few rows the app writes out: the parts give screen readers a table, the
// classes and the palette give it its look.
const invoices = [
  { id: "INV001", status: "Paid", method: "Card", amount: 250 },
  { id: "INV002", status: "Pending", method: "Transfer", amount: 150 },
  { id: "INV003", status: "Unpaid", method: "Card", amount: 350 },
  { id: "INV004", status: "Paid", method: "Cash", amount: 450 },
];
const widths = ["w-24", "flex-1", "w-24", "w-24"];

function Cell(props: { i: number; head?: boolean; end?: boolean; children: string }) {
  const style = { fontSize: size.label, color: props.head ? ui().muted : ui().text, fontWeight: props.head ? ("500" as const) : ("400" as const) };
  const Part = props.head ? TableHead : TableCell;
  return (
    <Part class={`${widths[props.i]} px-3 py-2.5`}>
      <Text style={{ ...style, textAlign: props.end ? "right" : "left" }}>{props.children}</Text>
    </Part>
  );
}

function App() {
  const line = { borderBottomWidth: 1, borderColor: ui().line };
  const total = invoices.reduce((sum, i) => sum + i.amount, 0);
  return (
    <Stage width={520}>
      <View style={{ ...ui().card, borderRadius: 12, overflow: "hidden" }}>
        <Table accessibilityLabel="Recent invoices">
          <TableHeader>
            <TableRow style={line}>
              {["Invoice", "Status", "Method", "Amount"].map((title, i) => (
                <Cell i={i} head end={i === 3}>
                  {title}
                </Cell>
              ))}
            </TableRow>
          </TableHeader>
          <TableBody>
            {invoices.map((inv) => (
              <TableRow style={line}>
                <Cell i={0}>{inv.id}</Cell>
                <Cell i={1}>{inv.status}</Cell>
                <Cell i={2}>{inv.method}</Cell>
                <Cell i={3} end>{`$${inv.amount.toFixed(2)}`}</Cell>
              </TableRow>
            ))}
          </TableBody>
          <TableFooter>
            <TableRow>
              <Cell i={0} head>Total</Cell>
              <Cell i={1}>{""}</Cell>
              <Cell i={2}>{""}</Cell>
              <Cell i={3} end>{`$${total.toFixed(2)}`}</Cell>
            </TableRow>
          </TableFooter>
          <TableCaption class="px-3 py-2">
            <Text style={{ fontSize: size.detail, color: ui().muted }}>A list of your recent invoices.</Text>
          </TableCaption>
        </Table>
      </View>
    </Stage>
  );
}

mount(App);
use nsh_base::{table, table_body, table_cell, table_head, table_header, table_row, theme};
use nsh_core::prelude::*;

fn invoices() -> impl IntoElement {
    let cell = |label: &'static str| table_cell().w(px(120.0)).px_3().py_2().child(text(label));
    table()
        .accessibility_label("Recent invoices")
        .child(
            table_header().child(
                table_row()
                    .border_b_1()
                    .border_color(move || theme().border)
                    .child(table_head().w(px(120.0)).px_3().py_2().child(text("Invoice")))
                    .child(table_head().w(px(120.0)).px_3().py_2().child(text("Amount"))),
            ),
        )
        .child(table_body().child(table_row().child(cell("INV001")).child(cell("$250.00"))))
}

Table और इसके भाग nsh/base से आते हैं, जो Rust में nsh-base क्रेट है, जहाँ table(), table_header(), table_body(), table_footer(), table_row(), table_head(), table_cell() और table_caption() इन्हें टाइप्ड स्टाइल मेथड और .child(..) के साथ बनाते हैं। एक पंक्ति अपने सेल साथ-साथ रखती है; ऐप सेल को उनकी चौड़ाई देता है, ताकि कॉलम एक सीध में रहें।

#प्रॉप्स

प्रॉपRustप्रकारडिफ़ॉल्टविवरण
accessibilityLabel.accessibility_label(..)stringकोई नहींकेवल Table के लिए: स्क्रीन रीडर तालिका को क्या नाम देते हैं।
children.child(..)JSX.Elementकोई नहींभाग में क्या होता है: Table में समूह और एक कैप्शन, समूह में पंक्तियाँ, पंक्ति में सेल, सेल में सामग्री।
class, styleस्टाइल मेथडstring, StyleProp<ViewStyle>कोई नहींभाग का रूप और लेआउट।

#भाग

भागभीतरस्क्रीन रीडर के लिए भूमिका
Tableतालिका
TableHeaderTableपंक्ति समूह: कॉलम हेडर की पंक्तियाँ
TableBodyTableपंक्ति समूह: डेटा की पंक्तियाँ
TableFooterTableपंक्ति समूह: कुल योग, एक सारांश पंक्ति
TableRowएक समूह, या Tableपंक्ति; इसके सेल साथ-साथ
TableHeadहेडर का एक TableRowकॉलम हेडर
TableCellTableRowसेल
TableCaptionTableवह सामग्री जो ऐप तालिका के बारे में दिखाता है

प्रत्येक प्लेटफ़ॉर्म अपने स्क्रीन रीडर को भूमिकाएँ देता है: Linux (AT-SPI), वेब (ARIA), Android और GPUI बैकएंड पर तालिका, पंक्ति, सेल और कॉलम हेडर की भूमिकाएँ; macOS और Windows पर ग्रिड और समूह; iOS पर हेडर के रूप में हेडर।

#यह भी देखें

  • DataTable: किसी भी संख्या में पंक्तियों और कॉलम की तालिका, चयन, सॉर्टिंग और आकार बदले जा सकने वाले, हटाए जा सकने वाले कॉलम के साथ।
  • Accessibility: accessibilityRole मान, table, row, cell, columnheader और rowgroup इन्हीं में शामिल हैं।